Created
January 8, 2016 19:51
-
-
Save tlkahn/77b2039f48cd652f6f39 to your computer and use it in GitHub Desktop.
angular directive embed and multiple transclude
This file contains hidden or 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
app.directive('outer', function(){ | |
return { | |
restrict: 'E', | |
controllerAs: 'outer', | |
require: 'outer', | |
template: '<p>{{outer.hello}}<p ng-transclude="outerInner"></p><p ng-transclude></p></p>', | |
scope: true, | |
transclude: { | |
outerInner: 'inner' | |
}, | |
controller: function(){ | |
this.sayHello = function(){ | |
console.log('outer: hello'); | |
}; | |
this.hello = "hello outer"; | |
}, | |
link: function(scope, element, attrs, outerCtrl){ | |
element.on('click', function(){ | |
outerCtrl.sayHello(); | |
}); | |
} | |
}; | |
}); | |
app.directive('inner', function(){ | |
return { | |
restrict: 'E', | |
template: '<p>{{inner.welcome}}</p>', | |
require: ['^outer', 'inner'], | |
scope: true, | |
controllerAs: 'inner', | |
controller: function(){ | |
this.sayWelcome = function(){ | |
console.log('inner: welcome'); | |
}; | |
this.welcome = "welome inner"; | |
}, | |
link: function(scope, element, attrs, ctrls){ | |
var outerCtrl = ctrls[0]; | |
var innerCtrl = ctrls[1]; | |
element.on('click', function(event){ | |
innerCtrl.sayWelcome(); | |
outerCtrl.sayHello(); | |
event.stopPropagation(); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment