首页 > Web开发 > 详细

angular(mvc)指令的嵌套使用

时间:2017-09-26 17:24:37      阅读:297      评论:0      收藏:0      [点我收藏+]

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

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

举一个例子:

有个指令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://www.cnblogs.com/evaling/p/7597472.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!