Sharping Up with Angularjs 1.x -Direactive

1、基本指令声明

eg:
  app.directive('productGallery', function(){
     return {
       restrict: 'E',
       templateUrl: 'product-gallery.html',
       controller: function(){
          this.current = 0;
          this.setCurrent = function(imageNumber){
          this.current = imageNumber || 0;
        };
       },
       controllerAs: 'gallery'
     };
  });

restrict - 声明指令的使用方法:
E: 作为标签使用 <poduct-allery></poduct-gallery>
A: 作为属性使用 <div poductGallery></div>
C: 同类名绑定 <div class="poductGallery"></div>
M: 作为注释使用,不推荐

templateUrl - 声明需要加载的html模板,可以是html文件路径,也可以是一个函数。(可以使用 ng-include 实现动态 templateUrl,但是否更适合使用 ng-route 实现还有待验证)

controller 中可声明形如

this.addStrength = function() {
    $scope.abilities.push("strength");
};

的函数,暴露给其他 direactive 调用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值