本文介绍了Angular2-错误如下:“例外:在MyComponent上找不到指令注释"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试从其他文件导入指令时,出现错误EXCEPTION: No Directive annotation found on MyComponent
-如何解决此问题?
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?
这是我的代码:
app.component.ts:
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:
app.mycomponent.ts:
import {Component} from 'angular2/core';
@Component({
selector : 'my-component',
template : `<h2>This is from My component</h2>`
});
export class MyComponent { };
但是我收到错误消息:No Directive annotation found on MyComponent
如何解决这个问题?
But i am getting error as : No Directive annotation found on MyComponent
how to solve this?
推荐答案
您应在组件关闭Component
指令括号后删除;
.
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 { };
这篇关于Angular2-错误如下:“例外:在MyComponent上找不到指令注释"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!