2017-03-09 57 views
1

我用指令:爲什麼不能在指令Angular JS中使用兩種綁定方式?

return { 
    restrict: 'E', 
    scope: { 
     isread: "=isread" 
    ,.... 
    templateUrl: 'list.html', 

其中list.html是:

<div class="top-menu" ng-controller="NotificationController"> 
    <notification-list isread="is_read"></notification-list> 
</div> 

而且NotificationController

scope.makeRead = function() { 
    $scope.is_read = true; 
} 
從那裏我稱之爲指令

<span ng-show="isread"></span> 

和家長trmplate

爲什麼當我在控制器中更改$scope.is_read = true;時,在變量isread中的指令中沒有更改?

+0

如何在控制器中檢查「is_read」正在更新爲true? –

+0

默認情況下它是:'$ scope.is_read = false'在控制器中 – Daniel

+0

檢查控制器中的$ scope.is_read是否更新爲true –

回答

0
return { 
restrict: 'E', 
scope: { 
    isread: "=" 
,.... 
templateUrl: 'list.html', 
+2

雖然此代碼片段可能會解決問題,但[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – DimaSan

相關問題