2014-06-28 23 views
0

我試圖使自定義NG-指令,通過傳遞給它作爲$屬性值上$scope.object.variable - 「object.variable」(就像NG-綁定一樣)

<my-directive shows="object.variable"> 

我不能」不知道如何ng-bind does it by looking at its source,但那正是我想要的。

it uses .ngBind?不適用於我,給我undefined)這是如何工作的?

回答

0

根據源ngBind的工作原理,根據ng-bind屬性的值設置$ watch。

scope.$watch(attr.ngBind, function ngBindWatchAction(value) { 
    // We are purposefully using == here rather than === because we want to 
    // catch when value is "null or undefined" 
    // jshint -W041 
    element.text(value == undefined ? '' : value); 
    }); 

當該值是未定義的(其將是如果結合表達從未初始化),然後它會與空文本替換元素的內容。

+0

'attr.ngBind'給我未定義。總是。我已經確定'attr'或者任何我傳遞給'.ngBind'的東西都有一個值,它對應於我的'$ scope'中的一個子對象,但它總是給我定義。 * * .ngBind'是什麼?它如何提取$ scope的值? – laggingreflex

+0

啊@ $ $!它是'ng-bind',屬性本身的名字!我應該傳遞'attr.show'來代替。 – laggingreflex

相關問題