Angular version 2.0.0-rc.4
test.component.ts
import {Component} from '@angular/core';
Component({
selector: 'test',
templateUrl: 'templates/test.tpl.html'
})
export class TestComponent{
}
my-component.component.ts
import {Component} from "@angular/core";
import {OnInit} from "@angular/core";
import {TestComponent} from "./test.component";
@Component({
selector: 'my-component',
template: `
I am <span [style.color]="inputElement.value === 'yes' ? 'red' : '' ">{{name}}</span>.
<br>
<br>
<span [class.it-awesome]="inputElement.value==='yes'">It awesome!</span>
<input type="text" #inputElement (keyup)="0"/>
<button [disabled]="inputElement.value !=='yes'">Only enabled if 'yes' was entered </button>
<test></test>
`,
styleUrls: ['assets/scss/mycomponent.scss'],
directives: [TestComponent]
})
export class MyComponentComponent implements OnInit {
name: string;
ngOnInit():any {
this.name = "Dima";
}
}
In console google chrome every time display error: No Directive annotation found on TestComponent. Why not found? name of file is test.component.ts.
There is a spelling error. Add a @ before component.
import {Component} from '@angular/core';
@Component({
selector: 'test',
templateUrl: 'templates/test.tpl.html'
})
export class TestComponent{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With