controllerAs

angular.module('myApp',[])
 .directive('bookList',function () {
      return{
          restrict:'ECAM',
          controller:function ($scope) {
              console.log($scope);
              $scope.books=[
                  {
                      name:'php'
                  },
                  {
                      name:'javascript'
                  },
                  {
                      name:'java'
                  }
              ];
           $scope.addBook=function () {
                  alert('e');
              }
          },
          controllerAs:'bookListController',
          template:'<ul><li ng-repeat="book in books">{{book.name}}</li></ul>',
          replace:true,
          link: function(scope,iElement,iAttrs,bookListController) {
              console.log(1);
            iElement.on('click',scope.addBook);
          }
      }
 })
 .controller('firstController',['$scope',function ($scope) {
   console.log($scope);


 }]);

  

posted @ 2017-10-18 16:40  zhujhhxx  阅读(129)  评论(0编辑  收藏  举报