2013-06-01 64 views
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)); 
     } 
    }; 
}); 

回答

1

其實你用自己的鞭子擊中頭上的釘子e行<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),這意味着該指令被傳遞給解析器,並且在大括號解析階段不會從解析器綁定。

你看到它在屬性情況下處理的原因是,預處理器(角度核心指令編譯器)不知道跳過你創建的屬性,所以它仍然處理它,然後將值作爲表達式發送剛回來。

相關問題