gpt4 book ai didi

Angular2 版本 RC.6 "directives"inside @Component Error

转载 作者:太空狗 更新时间:2023-10-29 16:53:06 24 4
gpt4 key购买 nike

我正在使用 Angular2 并从官方网站下载了 package.json。当我尝试在 @Component 装饰器中使用“指令”时,出现此错误。

我附上了我的代码错误:

[ts]
Argument of type '{ selector: string; template: string; directives: string;
}' is not assignable to parameter of type 'ComponentMetadataType'.

Object literal may only specific known properties, and 'directives' does not
exist in type 'ComponentMetadataType'.
(property) directives: string

这是我的代码:

import { Component } from '@angular/core';
import { PeopleListComponent } from './people-list/people-list.component';

@Component({
selector: 'my-app',
template: '<h1>{{ title }}</h1>',
directives: '' //ERROR //NOT ABLE TO RECOGNIZE
})

export class AppComponent {
title = "My title";
}

这是我的 package.json:

        {
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.6",
"@angular/compiler": "2.0.0-rc.6",
"@angular/compiler-cli": "0.6.0",
"@angular/core": "2.0.0-rc.6",
"@angular/forms": "2.0.0-rc.6",
"@angular/http": "2.0.0-rc.6",
"@angular/platform-browser": "2.0.0-rc.6",
"@angular/platform-browser-dynamic": "2.0.0-rc.6",
"@angular/router": "3.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.6",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.11",
"systemjs": "0.19.27",
"zone.js": "^0.6.17",
"angular2-in-memory-web-api": "0.0.18",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.2",
"typescript": "^1.8.10",
"typings":"^1.3.2"
}
}

最佳答案

简单...

问题出在 directives: ''

作为一个数组,它应该是 directives: [ ]

更新:在RC6以后的版本中,你有@NgModule .在 RC6 OR 更高版本中,您必须声明 pipesdirectives 您将在 @NgModule 中使用,如图所示...

import { PeopleListComponent } from './people-list/people-list.component';

@NgModule({
imports: [ BrowserModule],
declarations: [ AppComponent,PeopleListComponent ], //<<===here
providers: [],
bootstrap: [ AppComponent ]
})

您可以从 AppComponent< 的 @Component 中移除 directives:''/

关于Angular2 版本 RC.6 "directives"inside @Component Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39410591/

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