angular directive的写法

本文介绍了AngularJS中指令和控制器的基本用法及实例。包括使用angular.module创建模块,定义控制器并通过函数设置作用域变量,以及如何定义自定义指令等。这些示例展示了AngularJS在构建动态Web应用方面的强大能力。

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";
}]);

 

转载于:https://www.cnblogs.com/floraCnblogs/p/angular-directive-write.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值