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

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

举一个例子:

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

相关文章:

  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-10
  • 2022-12-23
  • 2021-10-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案