Angualr2 - 收到错误为:`例外:MyComponent`找不到指令注释 [英] Angualr2 - getting error as : `EXCEPTION: No Directive annotation found on MyComponent`

查看:101
本文介绍了Angualr2 - 收到错误为:`例外:MyComponent`找不到指令注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图导入从其他文件中的指令,我得到的误差例外:MyComponent的找不到指令注释 - 如何解决这个

这是我的code:

app.component.ts:

 进口{}组件从angular2 /核心;
从./app.my-component进口{} MyComponent的@零件({
    选择:应用程序,
    模板:`
        < H1> Hellow世界< / H1>
        <跨度>这里是您的组件:< / SPAN>
        <我-成分>< /我-成分>
    `
    指令:[MyComponent的]
})出口类AppComponent {}

app.mycomponent.ts:

 进口{}组件从angular2 /核心;@零件({    选择:我的组件,    模板:`< H2>这是我从组分LT; / H>`});出口类MyComponent的{};

但我正在逐渐误差:<?code>上没有找到MyComponent的指令注释如何解决这个


解决方案

您应该删除; 后部分结束组件指令括号。

 进口{}组件从angular2 /核心;@零件({选择:我的组件,模板:`&LT; H2&gt;这是我从组分LT; / H&GT;`})
出口类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?

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?

解决方案

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 { };

这篇关于Angualr2 - 收到错误为:`例外:MyComponent`找不到指令注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆