2016-10-12 89 views
0

方案雙向綁定不工作的嵌套指令 - AngularJS

我不想打開我的網頁上超過3個聊天窗口。雖然我能夠部分地管理的是,我想現在實現的是

再次顯示USER按鍵如有聊天窗口關閉(所以,如果他關閉所有用戶可以再次打開聊天窗口其中之一)

Here is the working plunker。我採取的雙向綁定

我處理,在此鏈接功能的護理:

link: function(scope, element, attr) { 
    scope.close = function(){ 
     element.hide(); 
     alert('scope.count not reducing the actual count on index.html') 
     scope.count--; // <-- THIS IS NOT DECRESING THE COUNT on main index.html 
    } 
    scope.$watch('box2', function(newIsOpenVal, oldIsOpenVal){ 
    if(newIsOpenVal !== oldIsOpenVal){ 
     element.find("#msg").toggle(); 
    } 
    }); 

} 
+0

我看不到雙向綁定,但我*做*看到兩個指令之間的隔離範圍。 – Makoto

+0

@Makoto:我在隔離範圍內保留了'count:'='' –

+0

是的,因此爲什麼我沒有看到兩者之間的任何雙向綁定。它們被有效隔斷。 – Makoto

回答

1

在您的實現問題是,您不使用從您的控制器的範圍count,解決它你應該這樣做:

$compile("<div chat-toggle user-name="+scope.userName+" count='count'></div>")(scope)