angular directive的写法

1. 

angular.module('MyApp', [])
.controller('Ctrl', function($scope) {
  vm = $scope;
})
.directive('multPicture', function() {
  return {
    replace: true,
    restrict: 'EA',
    scope: {
      pictures: "=",
      picHeight: "=",
      picWidth: "="
    },
    transclude: true,
    template: 'this is a directive',
    link: function(scope, element, attrs) {
    }
  }
});

2.常用

angular.module('MyApp',[])
.directive('zl1',zl1)
.controller('con1',['$scope',func1]);
function zl1(){
  var directive={
    restrict:'AEC',
    template:'this is the it-first directive',
  };
  return directive;
};
function func1($scope){
  $scope.name="alice";
}

3. 同二一个意思

angular.module('myApp',[])
.directive('zl1',[ function(){
  return {
    restrict:'AE',
    template:'thirective',
    link:function($scope,elm,attr,controller){
      console.log("这是link");
    },
    controller:function($scope,$element,$attrs){
      console.log("这是con");
    }
  };
}])
.controller('Con1',['$scope',function($scope){
  $scope.name="aliceqqq";
}]);

 

posted @ 2017-03-02 15:45  李晓菲  阅读(335)  评论(0编辑  收藏  举报