【问题标题】:Is there any maximum nesting level for angularjs directivesangularjs指令是否有最大嵌套级别
【发布时间】:2015-03-25 21:33:29
【问题描述】:

我有下一个指令:schemarecordfieldtype

在视图中,我使用模板中包含recordschema 指令。 在record 模板中使用了field 指令,在field 指令中使用了type 指令。 (嵌套级别 = 4)

  • 架构
    • 记录
      • 字段
        • 类型

字段指令代码:

.directive("field", function(){
    return {
        restrict: "E",
                replace: true,
                transclude: true,
                scope: {
                    field: '='
                },
                template: "<tr><td>{{field.name}}</td><type type='field.type'></type><td>{{field.type}}</td></tr>"
    }
  })

类型指令代码:

.directive("type", function($compile){
    return{
        restrict: "E",
        replace: true,
        transclude: true,
        scope: {
            type: '='
        },
        template: "<td>test</td>"
    }
  })

渲染fieldtype 指令的部分输出: size ["null","long"]type 指令评估没有结果)。

有趣的是,当我将type 指令高一级(在record 的模板内)时,一切都会正确呈现:

【问题讨论】:

    标签: angularjs angularjs-directive


    【解决方案1】:

    问题与field 指令的模板定义有关。 在 &lt;tr&gt; 标记内,您不能放置未被包围但 &lt;td&gt; 的内容,即使这是会生成适当包围 (&lt;td&gt;...&lt;/td&gt;) 的指令。

    将指令更新到下一个状态:

    字段:

    .directive("field", function(){
        return {
            restrict: "E",
                    replace: true,
                    transclude: true,
                    scope: {
                        field: '='
                    },
                    template: "<tr><td>{{field.name}}</td><td><type type='field.type'></type></td><td>{{field.type}}</td></tr>"
        }
      })
    

    类型:

     .directive("type", function($compile){
            return{
                restrict: "E",
                replace: true,
                transclude: true,
                scope: {
                    type: '='
                },
                template: "test"
    
            }
          })
    

    解决问题。

    【讨论】:

      猜你喜欢
      • 2012-12-29
      • 1970-01-01
      • 2016-05-17
      • 2014-04-10
      • 2016-10-14
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多