這會不會是一個完整的答案,但我可以用angularFire部分幫助,並可能是一個角度大師可以爲你填空(參見// todo)。
首先,不要試圖分享範圍。簡單地將你想要的變量傳遞給子範圍。既然你想要一個3路綁定,你可以使用&
來調用父範圍的方法。
例如,要建立這種模式:
<div ng-repeat="(key,widget) in widgets">
<data-widget bound-widget="getBoundWidget(key)"/>
</div>
你可以設置你的指令是這樣的:
.directive('dataWidget', function() {
return {
scope: {
boundWidget: '&boundWidget'
},
/* your directive here */
//todo presumably you want to use controller: ... here
}
});
凡& boundWidget調用一個方法在父$範圍如下所示:
.controller('ParentController', function($scope, $firebase) {
$scope.widgets = $firebase(/*...*/);
$scope.getBoundWidget = function(key) {
var ref = $scope.widgets.$child(key);
// todo, reference $scope.boundWidget in the directive??
ref.$bind(/*** ??? ***/);
};
});
現在你只需要有人來填寫//待辦事項部分!
我想你錯過了'$ watch'的部分。 'ng-repeat'必須爲每個項目創建一個子項目(非隔離)。也許與我們分享一些代碼,並告訴我們你已經嘗試了什麼。 –