angularjs添加html元素,AngularJS 指令

借用Alice的代码继续 关于自定义的指令内容解读

angular.module('myApp', []).directive('first', [ function(){

return {

scope: false, //默认值为 false 共享父作用域 值为true时共享父级作用域并创建指令自己的

controller: function($scope, $element, $attrs, $transclude) {}, //作用域 值为{}时创建全新的隔离作用域, 值为string时为控制器名称

restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment

template: 'first name:{{name}}',//值为string、function 用于显示dom元素

templateUrl: 'xxx.html' //值为string function 以id为xxx.html为 调用文件显示

priority: 0 //指明指令的优先级,若在dom上有多个指令优先级高的先执行

replace: flase // 默认值为false 当为true是直接替换指令所在的标签

terminal: true //值为true时优先级低于此指令的其它指令无效

link:function // 值为函数 用来定义指令行为从传入的参数中获取元素并进行处理

};

}]).directive('second', [ function(){

return {

scope: true,

// controller: function($scope, $element, $attrs, $transclude) {},

restrict: 'AE', // E = Element, A = Attribute, C = Class, M = Comment

//当修改这里的name时,second会在自己的作用域中新建一个name变量,与父级作用域中的

// name相对独立,所以再修改父级中的name对second中的name就不会有影响了

template: 'second name:{{name}}',

};

}])

.controller('DirectiveController', ['$scope', function($scope){

$scope.name="mike";

}]);

菜鸟

菜鸟

643***369@qq.com4年前 (2017-11-14)

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值