Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - getting error as : `EXCEPTION: No Directive annotation found on MyComponent`

Tags:

angular

when i trying to import a directive from other file, i am getting the error as EXCEPTION: No Directive annotation found on MyComponent - how to solve this?

here is my code:

app.component.ts:

import {Component} from 'angular2/core';
import {MyComponent} from "./app.my-component"

@Component({
    selector: 'app',
    template: `
        <h1>Hellow World</h1>
        <span>Here is your component:</span>
        <my-component></my-component>
    `,
    directives: [MyComponent]
})

export class AppComponent { }

app.mycomponent.ts:

import {Component} from 'angular2/core';

@Component({

    selector : 'my-component',

    template : `<h2>This is from My component</h2>`

});

export class MyComponent { };

But i am getting error as : No Directive annotation found on MyComponent how to solve this?

like image 682
3gwebtrain Avatar asked Mar 14 '16 07:03

3gwebtrain


1 Answers

You should remove ; after component closing Component directive parenthesis.

import {Component} from 'angular2/core';

@Component({

selector : 'my-component',

template : `<h2>This is from My component</h2>`

})
export class MyComponent { };
like image 191
Turdaliev Nursultan Avatar answered Nov 15 '22 10:11

Turdaliev Nursultan