<!DOCTYPE html>
<html>
<body ng-controller="sayHello">
. . .
</body>
</html>
Eine Markierung auf einem HTML-TAG, die Angular auffordert Javascript zu referenzieren oder auszufüren.
function sayHello(){
alert("Hello Simon");
}
In einem Controller wird mittels Variablen und Funktionen das Verhalten der Applikation gesteuert.
var myApp = angular.module('myApp',[]);
myApp.controller('DoubleController', ['$scope', function($scope) {
$scope.double = function(value) { return value * 2; };
}]);
<div ng-controller="DoubleController">
Two times <input ng-model="num"> equals {{ double(num) }}
</div>
Angular services are substitutable objects that are wired together using dependency injection (DI). You can use services to organize and share code across your app.
// Simple GET request example :
$http.get('/someUrl').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
Buil-in Services (beginnen mit $).
Z.B. $http
jQuery.get() = $http.get()
jQuery.post() = $http.post()
Der Scope ist das Verbindungs- stück zwischen View und Controller.
Ein Module ist ein Container der die verschiedenen Teile (controllers, services, filters, directives, etc.) einer Applikation enthält.
Seit 2014
.directive('myIMG', function() {
return {
restrict: 'E',
templateUrl: 'img.html',
template: "<img src='scope.path'>",
transclude: true,
scope: {
path: '='
},
link: function(scope, element, attr) {
}
};
});
<myIMG path=''></myIMG>
HTML