web-dev-qa-db-fra.com

Angular2 version RC.6 "directives" dans @Component Error

J'utilise Angular2 et j'ai téléchargé package.json sur le site officiel. Lorsque j'essaie d'utiliser des "directives" dans le décorateur @Component, j'obtiens cette erreur.

J'ai joint mon code ERREUR:

[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

Voici mon code:

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

Voici mon 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"
          }
        }
21
Shashank Gaurav

simple...

le problème est avec directives: ''

comme son tableau, il devrait être directives: [ ]

Mise à jour: Dans RC6 OU version ultérieure, vous avez @NgModule. Dans RC6 OU version ultérieure, vous devez déclarer pipes et - directives que vous allez utiliser dans @NgModule comme indiqué ...

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

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

Vous pouvez supprimer directives:'' de @Component sur AppComponent

26
micronyks

directives et pipes à l'intérieur @Component est déconseillé de angular RC6. Vérifiez ma réponse sur https://stackoverflow.com/questions/39410417/how-to-import-component-into-another-root -composant-en-angulaire-2

12
ranakrunal9