Skip to content

Instantly share code, notes, and snippets.

@timkindberg
Created December 9, 2015 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timkindberg/d0902b7048280f1141a4 to your computer and use it in GitHub Desktop.
Save timkindberg/d0902b7048280f1141a4 to your computer and use it in GitHub Desktop.
Example of Directives Injecting Directives
import {Component, bootstrap} from 'angular2/angular2';
import {Tabs} from "./Tabs";
import {Tab} from "./Tab";
@Component({
selector: 'hello-app',
directives: [Tabs, Tab],
template: `
// Doesn't work
<div tabs>
<div tab></div>
</div>
// Doesn't work either
<div tabs tab></div>
`
})
export class HelloApp {}
bootstrap(HelloApp);
import {Directive, ElementRef} from 'angular2/angular2';
import {Tabs} from './tabs';
@Directive({
selector: '[tab]'
})
export class Tab {
constructor(el: ElementRef, tabs: Tabs) {
console.log('Tabs:', tabs);
}
}
import {Directive, ElementRef} from 'angular2/angular2';
@Directive({
selector: '[tabs]'
})
export class Tabs {
constructor(el: ElementRef) {
console.log('Tabs:', el);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment