HTML部分
<index></index>
指令
angular.module('todoWithAngularApp').directive('index', function () {
return {
restrict: 'E',
templateUrl: '/scripts/template/index.html',
replace: true,
link: function (scope, iElement, iAttrs) {
console.log(scope);
console.log(iElement);
console.log(iAttrs);
iElement.on('click', '#addTaskClass', function(event) {
scope.addTaskClassBoxDisplay = true;
console.log(scope.addTaskClassBoxDisplay);
})
}
};
控制器
angular.module('todoWithAngularApp').controller('IndexCtrl', function ($scope) {
$scope.addTaskClassBoxDisplay = false;
});
怎样才能让指令去修改控制器上的$scope的属性
不负责任未经验证的提供几个思路:
1.把addTaskClassBoxDisplay放到对象下面,例如
scope.obj.addTaskClassBoxDisplay = true
2.使用消息
3.使用service
以上3种方法也是angular通用的模块间共享数据的方式,可分别适应不同场景。