gpt4 book ai didi

Angular2 - 收到错误 : `EXCEPTION: No Directive annotation found on MyComponent`

转载 作者:太空狗 更新时间:2023-10-29 17:21:38 27 4
gpt4 key购买 nike

当我尝试从其他文件导入指令时,出现错误,如 EXCEPTION: No Directive annotation found on MyComponent - 如何解决这个问题?

这是我的代码:

应用程序组件.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 { };

但我收到错误消息:在 MyComponent 上找不到指令注释 如何解决这个问题?

最佳答案

您应该在组件关闭 Component 指令括号后删除 ;

import {Component} from 'angular2/core';

@Component({

selector : 'my-component',

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

})
export class MyComponent { };

关于Angular2 - 收到错误 : `EXCEPTION: No Directive annotation found on MyComponent` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35981553/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com