Created
May 27, 2016 12:29
-
-
Save oksuz/35602588ed2b94ef3d559c503ffa48c7 to your computer and use it in GitHub Desktop.
access parent scope attribute in directive's link function through child directive's attribute using bindToController feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// plunker | |
// http://plnkr.co/edit/fYTqD8qYPcULRKZ2zqdA | |
(function() { | |
var app1 = angular.module('myApp1', ['myApp2']); | |
app1.directive('myApp', function() { | |
return { | |
scope: {}, | |
template: '<inside-directive chart-config="vm.chartConfig"></inside-directive>', | |
bindToController: true, | |
controller: function () { | |
this.chartConfig = { | |
'test': true | |
}; | |
}, | |
controllerAs: 'vm' | |
}; | |
}); | |
var app2 = angular.module('myApp2', []); | |
app2.directive('insideDirective', function() { | |
return { | |
scope: { | |
chartConfig: '=?' | |
}, | |
bindToController: { | |
chartConfig: '=?' | |
}, | |
template: '<b>Hello from inside directive</b>.', | |
controller: function () {}, | |
controllerAs: 'vm', | |
link: function (scope, elem, attr, ctrl) { | |
elem.append(JSON.stringify(scope.chartConfig)) | |
} | |
}; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment