Created
December 9, 2015 16:06
-
-
Save timkindberg/d0902b7048280f1141a4 to your computer and use it in GitHub Desktop.
Example of Directives Injecting Directives
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
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); |
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
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); | |
} | |
} |
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
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