摘要:AngularJs(二)
ng-app
宣告開始使用angularJS 通常放置html標籤內
<!doctype html>
<html ng-app>
<head>
<script src="http://code.angularjs.org/1.0.6/angular.min.js"></script>
</head>
<body>
I can add: 1 + 2 = {{ 1+2 }}
</body>
</html>
ng-bind
替換html標籤內文字 可與{{}}替換使用
<input type="text" ng-model="name">
text:{{name}}
<input type="text" ng-model="name">
text:<span ng-bind="name"></span>
ng-bind-template
與ng-bind類似 相差於ng-bind無法加入{{}}使用
<input type="text" ng-model="name">
text:{{name}}
<input type="text" ng-model="name">
text2:<span ng-bind-template="{{name}}"></span>
directives
var myModule = angular.module(...);
myModule.directive('directiveName', function factory(injectables) {
var directiveDefinitionObject = {
priority: 0,
template: '<div></div>',
templateUrl: 'directive.html',
replace: false,
transclude: false,
restrict: 'A',
scope: false,
controller: ["$scope", "$element", "$attrs", "$transclude", "otherInjectables",
function($scope, $element, $attrs, $transclude, otherInjectables) { ... }],
compile: function compile(tElement, tAttrs, transclude) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) { ... },
post: function postLink(scope, iElement, iAttrs, controller) { ... }
}
},
link: function postLink(scope, iElement, iAttrs) { ... }
};
return directiveDefinitionObject;
});