I'm trying to have Two-Way binding on a directive.
I can't use the scope on the directive (multiple directives on element), so I'll have to do it in the compile(){...} function
This is a simplified version of the directive so far:
.directive('myDialog', function() {
return {
restrict: 'E',
templateUrl: 'my-dialog.html',
compile: function(tElement, tAttrs, transclude) {
return function($scope, $element, $attributes) {
$scope.label = $scope.$eval($attributes.label);
// when I set the label on something this should update the parent
$scope.label = "test";
}
}
};
So how can I make it that when I change the lable in my directive it updates the value in the main application, and visa versa
Plunker for testing: http://plnkr.co/edit/lARCrGD5FsnOWQZrahIl?p=preview
UPDATE: here is the actual setup with all the logic for what I'm trying to archieve: http://codepen.io/cskiwi/pen/eJryqK?editors=1010
On line 101 i want to set the testing var on true, later one I'm also going to set to testing var on false outside that directive
UPDATE2: Got something, that is maybe something to lookinto:
return {
restrict: "A",
require: ["^mdChips", "^chipBar"],
controller: "chipBarController",
controllerAs: "chipBarController",
bindToController: {
activated: "="
},
// rest of the code
this is allowing to set the activated var to true from in the directive; but now I can't set the value from my appCtrl back to false
controllerAsand$scope, and trying to use both at the same time, which will be more trouble than it's worth. I'm going to try to decipher the codepen and offer some advice, but I can't guarantee anything.ifstatements to change templates, along with some rather unusual references to things like$$replacedScope.... It seems like there are multiple ways that this could be refactored, and once refactored, your current issue would be easier to deal with.