angular(mvc)指令的嵌套使用

关于指令嵌套的使用,取值问题。

原理类似于控制器中使用指令,父指令类似于控制器,子指令就类似于控制器中指令。通过传值方式‘=’,我们直接可以在父指令中获取数据

举一个例子:

有个指令parentDirective
模板文件是:parentHtml

还有一个childDirective
myapp.directive("childDirective",[function(){
  return{
    template:'....../childHtml',
    link:function(){
      ngModel:'='
    }
  } }]);
模板文件:childHtml
在parentDirective中引入childDirective
myapp.directive("parentDirective",
'.../js/directive/childDirective'
[function(){ return{
    template:'....../parentHtml.html',
    link:function(s,el,attr){
      s.$watch('giveData',function(n,o){
         console.log(n);     
      });
    }
  } }]);
parentHtml.html
<child-directive ng-model="giveData"></child-directive>

 

如果你想互相引用指令的控制器,你可以看看下面的文章链接

http://blog.csdn.net/zhoukun1008/article/details/51296692

转载于:https://www.cnblogs.com/evaling/p/7597472.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值