Last active
August 29, 2015 14:23
-
-
Save travenasty/540260a600f2b4103784 to your computer and use it in GitHub Desktop.
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
| /// <reference path="../../typings/angular2/angular2.d.ts" /> | |
| import {Component, View, NgIf, ElementRef} from 'angular2/angular2'; | |
| import {Inject} from 'angular2/di'; | |
| @Component({ | |
| selector: 'foo-component', | |
| injectables: [ElementRef] | |
| }) | |
| @View({ | |
| directives: [NgIf], | |
| template: ` | |
| <b>COMPONENT-TEMPLATE HERE!</b> | |
| ` | |
| }) | |
| class FooComponent { | |
| constructor(@Inject(ElementRef) ngEl:ElementRef) { | |
| console.log("this:", this); | |
| console.log("dom.element:", ngEl.domElement); | |
| } | |
| } | |
| exports.Foo = FooComponent; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is based on:
https://angular.io/docs/js/latest/api/directives/CSSClass-class.html
... and from poking around the src, and trying to mimic:
https://github.com/angular/angular/blob/master/modules/angular2/test/directives/non_bindable_spec.ts
I was wrestling with the following error:
ERROR: Cannot resolve all parameters for FooComponent. Make sure they all have valid type or annotations.
The fix thanks to help from: https://github.com/ericmdantas is to @Inject the reference of the dependency.
Note: angular2 version: https://code.angularjs.org/2.0.0-alpha.26/angular2.dev.js