Angular2 - getting error as : `EXCEPTION: No Directive annotation found on MyComponent`
13,766
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 { };
Related videos on Youtube
Author by
3gwebtrain
I am a front end developer living in chennai at India. i interested in html,css,seo,jquery,mobile,w3c standards and so on...
Updated on September 15, 2022Comments
-
3gwebtrain over 1 year
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? -
3gwebtrain about 8 yearsif i use
import {MyComponent} from "../app.my-component";
then i am getting error as : systemjs throws error as :http://localhost:3001/app.my-component 404 (Not Found)
in case if i use your second suggesion i am getting error asNo Directive annotation found on MyComponent
-
John about 8 yearsSorry I could not be of any help. Have look at the code from this blog post: blog.edenmsg.com/angular2-typescript-gulp-and-expressjs . Maybe you will find the source to your problems from it. I used that post as a reference when creating my first angular 2 application.
-
Turdaliev Nursultan about 8 yearsIs your file name 'app.mycomponent.ts' or 'app-mycomponent.ts'?
-
3gwebtrain about 8 yearsmy file name is
app.my-component.ts
- -
micronyks about 8 yearsnow try with full static path and tell us for which path it works correctly?
-
3gwebtrain about 8 years@micronyks - here is my app dropbox.com/s/xdahp4e8g07dvaz/demo.zip?dl=0 download and have a look
-
Turdaliev Nursultan about 8 years@3gwebtrain, I have created a
plunkr
code, and it's working, a ";" was the problem, you can check by putting it and looking atconsole
. plnkr.co/edit/GLdViZfwAoWRx99g6k7E?p=preview -
Turdaliev Nursultan about 8 yearsMaybe, you did not transpile typescript into js?
-
3gwebtrain about 8 yearsi do. can you please download my file and see?
-
Turdaliev Nursultan about 8 yearsYes I am looking at it, can you please look into plunker as well?
-
Turdaliev Nursultan about 8 yearsIt's
});
maan. You should set it to})
. Remove;
It was on your code you provided. You didn't remove it as I said. It's onapp.my-component.ts
file. -
3gwebtrain about 8 yearsyes. this is my bad. i have removed around other than the function. but it should not be the case to break the app. !
-
Turdaliev Nursultan about 8 yearsIt is the case breaking the app, I checked
-
3gwebtrain about 8 yearsLet us continue this discussion in chat.
-
watzon about 8 yearsThanks! I had this same problem and was trying to solve it for at least an hour!
-
Sander about 8 yearseuh, so after deleting this solution from my code, cause i was not happy with it as the 'end solution', i thought it would crash again... but it didnt... very very weird. Cache problem maybe?
-
mautrok almost 8 yearssorry but i have the same problem, anyone had found a solution? and most of all, isn't an error really strange and too much generic? is there a way to debug it? for example my problem is on @injectable() directive.