码迷,mamicode.com
首页 > 其他好文 > 详细

controller和controllerAs

时间:2017-10-18 18:22:52      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:book   repeat   replace   fun   attr   tco   add   turn   lis   

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(scope);
            iElement.on(‘click‘,scope.addBook);
          }
      }
 })
 .controller(‘firstController‘,[‘$scope‘,function ($scope) {
   console.log($scope,1);


 }]);

  

controller和controllerAs

标签:book   repeat   replace   fun   attr   tco   add   turn   lis   

原文地址:http://www.cnblogs.com/zhuj/p/7687980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!