AngularJS Spiekbriefje
AngularJS is een JavaScript-framework.
Lijst (ng-repeat)
<ul ng-controller="MyListCtrl">
<li ng-repeat="phone in phones">
{{phone.name}}
</li>
</ul>Model (ng-model)
<select ng-model="orderProp">
<option value="name">Alphabetical</option>
<option value="age">Newest</option>
</select>Een module definiëren
App = angular.module('myApp', []);
App.controller('MyListCtrl', function ($scope) {
$scope.phones = [ ... ];
});Voorkom controller-minificatie
App.controller('Name', [
'$scope',
'$http',
function ($scope, $http) {
}
]);
a.c 'name', [
'$scope'
'$http'
($scope, $http) ->
]Services
App.service('NameService', function($http){
return {
get: function(){
return $http.get(url);
}
}
});Aanroepen met parameters in de controller maakt gebruik van promises om gegevens van de server terug te sturen.
App.controller('controllerName',
function(NameService){
NameService.get()
.then(function(){})
})Directives
App.directive('name', function(){
return {
template: '<h1>Hello</h1>'
}
});In HTML wordt <name></name> gebruikt om je template <h1>Hello</h1> te renderen.
HTTP
App.controller('PhoneListCtrl', function ($scope, $http) {
$http.get('/data.json').success(function (data) {
$scope.phones = data;
})
});Referentie: