Angular 2 - 属性指令语法错误..我错过了什么吗?
Angular 2 - Error on attribute directive syntax..has i missed anything?
我的错误:
ERROR in C:/smartphoneSalesApp/src/app/test.directive.ts (9,3): Declaration expe
cted.
ERROR in C:/smartphoneSalesApp/src/app/dashboard/dashboard.component.ts (7,3): A
rgument of type '{ selector: string; templateUrl: string; directives: typeof tes
tDirective[]; }' is not assignable to parameter of type 'Component'.
Object literal may only specify known properties, and 'directives' does not ex
ist in type 'Component'.
我的组件代码:
import { Component } from '@angular/core';
import { testDirective } from '../test.directive';
@Component({
selector: 'dashboard',
templateUrl: './dashboard.component.html',
directives: [testDirective]
})
export class DashboardComponent {
title = 'Welcome to Dashboard';
}
我不知道为什么会收到此错误。我是否需要导入与指令相关的任何 angular 核心模块..??
您的代码有两个问题:
- 指令 属性 在
@Component
装饰器中不再受支持,所以你只需要在 @NgModule
中注册指令
- 你这里多了一个分号:
@Directive({se... 'onMouseLeave()'}}); <----
我的错误:
ERROR in C:/smartphoneSalesApp/src/app/test.directive.ts (9,3): Declaration expe
cted.
ERROR in C:/smartphoneSalesApp/src/app/dashboard/dashboard.component.ts (7,3): A
rgument of type '{ selector: string; templateUrl: string; directives: typeof tes
tDirective[]; }' is not assignable to parameter of type 'Component'.
Object literal may only specify known properties, and 'directives' does not ex
ist in type 'Component'.
我的组件代码:
import { Component } from '@angular/core';
import { testDirective } from '../test.directive';
@Component({
selector: 'dashboard',
templateUrl: './dashboard.component.html',
directives: [testDirective]
})
export class DashboardComponent {
title = 'Welcome to Dashboard';
}
我不知道为什么会收到此错误。我是否需要导入与指令相关的任何 angular 核心模块..??
您的代码有两个问题:
- 指令 属性 在
@Component
装饰器中不再受支持,所以你只需要在@NgModule
中注册指令
- 你这里多了一个分号:
@Directive({se... 'onMouseLeave()'}}); <----