您的位置:首页 > Web前端 > AngularJS

angularJs初学遇到的坑之directive

2016-05-19 17:43 387 查看

angularJs初学遇到的坑之directive

上代码:

js部分

angular.module('indexApp',[])
.directive('increasea',function(){
return function (scope,element,attr){
element.on("click",function(){
scope.a++;
scope.$digest();
});
};
})
.controller('indexContrl',function($scope){

$scope.a = 1;
$scope.$watch('a',function(newVal){
console.log('a:'+newVal);
});
});
```html部分:

<div class="se-preview-section-delimiter"></div>


<div ng-controller="indexContrl">
<button increasea>点击</button>
<span>点击次数:</span><span ng-bind="a"></span>
</div>


“`

其中directive的名字必须小写,increasea,如果是increase-a出错,increaseA也出错!!都是坑啊,孩纸们。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息