Skip to content

Instantly share code, notes, and snippets.

@jens1101
Created October 18, 2016 08:56
Show Gist options
  • Select an option

  • Save jens1101/45ff582fcf8845ef42c374194657359b to your computer and use it in GitHub Desktop.

Select an option

Save jens1101/45ff582fcf8845ef42c374194657359b to your computer and use it in GitHub Desktop.
Angularjs basic transclusion with require
angular.module('testApp', [])
.component('parent', {
template: '<h2>{{$ctrl.title}}</h2><div ng-transclude></div>',
transclude: true,
controller: function() {
this.title = 'Foobar'
}
})
.component('child', {
require: {
parent: '^parent'
},
controller: function() {
this.$onInit = function() {
console.log(this.parent);
};
}
});
<div ng-app="testApp">
<parent>
<p>Bacon ipsum dolor amet doner burgdoggen fatback salami shoulder brisket, shankle ribeye tongue chicken. Biltong andouille tenderloin tail burgdoggen tri-tip pork belly drumstick alcatra ham hock kevin. Frankfurter andouille salami, beef ribs sausage
kielbasa strip steak tenderloin biltong turkey meatball.</p>
<child></child>
</parent>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment