Skip to content

Instantly share code, notes, and snippets.

@travenasty
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save travenasty/540260a600f2b4103784 to your computer and use it in GitHub Desktop.

Select an option

Save travenasty/540260a600f2b4103784 to your computer and use it in GitHub Desktop.
/// <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;
@travenasty
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment