标签:[] console return func blog scope book script template
angular.module(‘myApp‘,[]) //require可以将其他指令传递给自己 //directivename:通过驼峰法的命名指定了控制器应该带有哪一条指令,默认会从同一个元素上的指令 //^directivename:在父级查找指令 //?directivename:表示指令是可选的,如果找不到,不需要抛出异常 .directive(‘bookList‘,function () { return { restrict:‘ECAN‘, controller:function ($scope) { console.log($scope); $scope.books=[ {name:‘php‘}, {name:‘javascript‘}, {name:‘java‘} ]; this.addBook=function () { alert(1); $scope.$apply(function () { $scope.books.push({ name:‘Angularjs‘ }) }) } }, controllerAs:‘bookListController‘, template:‘<div><ul><li ng-repeat="book in books">{{book.name}}</li></ul><book-add></book-add></div>‘, replace:true } }) .directive(‘bookAdd‘,function () { return{ restrict:‘ECAN‘, require:‘^bookList‘, template:‘<button type="button">添加</button>‘, replace:true, link:function (scope,iElement,iAttrs,bookListController) { console.log(scope) //iElement.on(‘click‘,bookListController.addBook); } } }) .controller(‘firstController‘,[‘$scope‘,function ($scope) { }]);
标签:[] console return func blog scope book script template
原文地址:http://www.cnblogs.com/zhuj/p/7687987.html