mardi 19 août 2014

AngularJS - Two-way binding with directive that takes variable number of parameters?


Vote count:

0




I'm working on an inline-editor directive that takes a whole slew of parameters (wrapped into one big object to keep things clean). So far I have this on the parent scope:



$scope.inlineEditParams = {
rendererUrl: null,
content: {
body: {
selector: "#content-body",
value: $scope.content.body
}
}
};


This is how I'm injecting the directive in the template:



<div inline-edit params="inlineEditParams"></div>


And I take the parameter onto the scope of the directive in the obvious way:



scope: {
params: '='
}


So obviously changes to the inlineEditParams object are reflected in both the directive and parent controller. But how can I get two-way binding going between the parent $scope.content.body and the inlineEditParams.content.body values, so that changes by either the parent controller or the directive will be reflected on both immediately? I don't want to pass in the parent $scope.content, since the directive expects the parameters to be formatted a specific way.



asked 21 secs ago

Nick

46






AngularJS - Two-way binding with directive that takes variable number of parameters?

Aucun commentaire:

Enregistrer un commentaire