Skip to content

Instantly share code, notes, and snippets.

@oksuz
Created May 27, 2016 12:29
Show Gist options
  • Save oksuz/35602588ed2b94ef3d559c503ffa48c7 to your computer and use it in GitHub Desktop.
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
// 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