0

Plunker:http ://plnkr.co/edit/XBJjr6uR1rMAg3Ng7DiJ?p=preview

我希望这两个看起来一样:

<span dt-attrib="{{person.name}}">This won't be here</span><br/>
<span class="dt-class: {{person.name}};">This won't be here.</span> - this does not process

但这就是我得到的:

This text was set by the dtAttrib directive, value="Burt Finklestein"
This text was set by the dtClass directive, value="{{person.name}}"

代码:

app.directive("dtAttrib", function() {
    return {
        restrict: "A",
        link: function(scope, element, attrs) {
            element.text('This text was set by the dtAttrib directive' + DisplayValueString(attrs.dtAttrib));
            }
        }
    }
});

app.directive("dtClass", function() {
    return {
        restrict: "C",
        link: function(scope, element, attrs) {
            element.text('This text was set by the dtClass directive' + DisplayValueString(attrs.dtClass));
        }
    };
});
4

1 回答 1

1

实际上,你用线在你自己的plunker中击中了头<span class="dt-class-b: person.name;">This won't be here.</span> - this DOES process, with no curly braces。类指令采用 C - Class: 形式<div class="my-directive: exp;"></div>(参见http://docs.angularjs.org/guide/directive),这意味着指令被传递给解析器并从那里绑定,而不是在大括号解析阶段。

您在属性情况下看到它处理的原因是预处理器(角度核心指令编译器)不知道跳过您创建的属性,因此它仍然处理它然后将值作为表达式发送,该表达式将返回。

于 2013-06-01T03:40:56.010 回答