繁体   English   中英

Angular2版本RC.6“指令”在@Component错误中

[英]Angular2 version RC.6 “directives” inside @Component Error

我正在使用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 更高版本中,您必须声明要在@NgModule使用的pipesdirectives ,如图所示......

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

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

您可以从AppComponent @Component中删除directives:''

@Component directivespipes @Component角度RC6中。 https://stackoverflow.com/questions/39410417/how-to-import-component-into-another-root-component-in-angular-2上查看我的答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM