码迷,mamicode.com
首页 > Web开发 > 详细

angular(mvc)指令的嵌套使用

时间:2017-09-26 17:46:42      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:http   app   detail   temp   指令   console   文章   return   引入   

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

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

举一个例子:

有个指令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

angular(mvc)指令的嵌套使用

标签:http   app   detail   temp   指令   console   文章   return   引入   

原文地址:http://www.cnblogs.com/evaling/p/7597472.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!