这会不会是一个完整的答案,但我可以用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'必须为每个项目创建一个子项目(非隔离)。也许与我们分享一些代码,并告诉我们你已经尝试了什么。 –