【问题标题】:Directive stop working when is nested with another?指令在与另一个嵌套时停止工作?
【发布时间】:2015-01-16 01:24:47
【问题描述】:

我正在尝试在示例上嵌套一些指令,看起来我得到了我需要的一切,但没有按预期工作,但是如果我将嵌套指令从父指令中取出,它就会被识别

    here is a plunker:http://plnkr.co/edit/eZaYTHm274zWx8GPMAS0?p=preview

这种嵌套指令的主要目的是在控制器之间共享数据并动态构建一组字段。

提前致谢!

资源:https://docs.angularjs.org/guide/directive

【问题讨论】:

  • 首先,将代码的相关部分发布到问题本身中。这个问题应该是自我维持的。其次,您有restrict: E,但使用指令作为属性。将限制更改为restrict: EA

标签: angularjs directive


【解决方案1】:

您的代码有两个问题:restrict 属性和 transclude/template 属性。请参阅下面的代码摘录。

return {
    restrict: 'AE', //You need to add "A" if you are using attributes
    transclude: true, // You need to include the ng-transclude directive in your template
    template: '<div> Some Html <div ng-transclude></div></div>',
    ...
};

【讨论】:

  • 感谢@Cory,并对我认为它已更新(代码)的限制感到抱歉。
  • 哦,有道理;我经常忘记用 plunker“冻结”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多