Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 2 - No Directive annotation found on TestComponent

Tags:

angular

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.

like image 780
dev85 Avatar asked Sep 09 '26 21:09

dev85


1 Answers

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{

}
like image 141
muetzerich Avatar answered Sep 12 '26 15:09

muetzerich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!