@H_404_0@本文实例讲述了AngularJS实现自定义指令及指令配置项的方法。分享给大家供大家参考,具体如下:
@H_404_0@<span style="font-size: medium">
AngularJS自定义指令有两种写法:
<div class="jb51code">
<pre class="brush:js;">
//第一种
angular.module('MyApp',[])
.directive('zl1',zl1)
.controller('con1',['$scope',func1]);
function zl1(){
var directive={
restrict:'AEC',template:'this is the it-first directive',};
return directive;
};
function func1($scope){
$scope.name="alice";
}
//第二种
angular.module('myApp',[]).directive('zl1',[ function(){
return {
restrict:'AE',template:'thirective',link:function($scope,elm,attr,controller){
console.log("这是link");
},controller:function($scope,$element,$attrs){
console.log("这是con");
}
};
}]).controller('Con1',function($scope){
$scope.name="aliceqqq";
}]);