详解Directive(指令)机制
E 表示该指令是一个element;
<html ng-app='app'>
<body>
<hello></hello>
</body>
<script src="../angular-1.0.3/angular.min.js"></script>
<script>
var appModule = angular.module('app', []);
appModule.directive('hello', function() {
return {
restrict: 'E',
template: '<div>Hi there</div>',
replace: true
};
});
</script>
</html>
A 表示该指令是attribute;
<html ng-app='app'>
<body>
<div style="width:100px;height:100px;" hello-world></div>
</body>
<script src="../angular-1.0.3/angular.min.js"></script>
<script>
var appModule = angular.module('app', []);
appModule.directive('helloWorld', function() {
return {
restrict: 'A',
template: '<div>Hi there</div>',
replace: true
};
});
</script>
</html>
C 表示该指令是class;
<html ng-app='app'>
<body>
<div class="hello"></div>
</body>
<script src="../angular-1.0.3/angular.min.js"></script>
<script>
var appModule = angular.module('app', []);
appModule.directive('hello', function() {
return {
restrict: 'C',
template: '<div>Hi there</div>',
replace: true
};
});
</script>
</html>
M 表示该指令是注视(没用过,待补充)