2017-07-06 76 views
0

我建立一個簡單的AngularJS 2/s的應用程序,我嘗試從一個嵌套的子組件到父組件傳遞變量,所以家長可以改變它,就像這樣:未捕獲的錯誤:模塊「AppModule」導入的意外值「PropDecoratorFactory」。請添加註釋@NgModule

兒童:


          
  
@Component({ 
 
     selector: 'app-copm-player', 
 
     templateUrl: './copm-player.component.html', 
 
     styleUrls: ['./copm-player.component.css'] 
 
    }) 
 
    export class CopmPlayerComponent implements OnInit { 
 
     // @Input('isRoundStart') isRoundStart: boolean = false; 
 
     isRoundStart: boolean = false; 
 
     // @Input('RandNum') randNums = 0; 
 
     randNums = 0; 
 
     constructor() { } 
 
     ngOnInit() { 
 
     } 
 

 
    }

家長:


          
  
import { Component, OnInit, ViewChild, Input} from '@angular/core'; 
 
    import {CopmPlayerComponent} from './copm-player/copm-player.component'; 
 

 
    @Component({ 
 
     selector: 'app-players-board', 
 
     templateUrl: './players-board.component.html', 
 
     styleUrls: ['./players-board.component.css'], 
 

 
    }) 
 
    export class PlayersBoardComponent implements OnInit { 
 
     @ViewChild(CopmPlayerComponent) compPlayer: CopmPlayerComponent; 
 
     onStartRound(){ 
 
     console.log(this.compPlayer.isRoundStart); 
 
     
 
     this.compPlayer.isRoundStart = true; 
 
     console.log(this.compPlayer.isRoundStart); 
 
     
 
     } 
 
     constructor() { } 
 

 
     ngOnInit() { 
 
     } 
 

 
    }

我的IDE說,沒有probem,但是當我嘗試運行整個應用程序我得到這個錯誤訊息話題:

> Uncaught Error: Unexpected value 'PropDecoratorFactory' imported by the module 'AppModule'. Please add a @NgModule annotation. 
    at syntaxError (compiler.es5.js:1689) 
    at compiler.es5.js:15373 
    at Array.forEach (<anonymous>) 
    at CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:15356) 
    at JitCompiler._loadModules (compiler.es5.js:26679) 
    at JitCompiler._compileModuleAndComponents (compiler.es5.js:26652) 
    at JitCompiler.compileModuleAsync (compiler.es5.js:26581) 
    at PlatformRef_._bootstrapModuleWithZone (core.es5.js:4595) 
    at PlatformRef_.bootstrapModule (core.es5.js:4581) 
    at Object.107 (main.ts:10) 

的奇怪的事情是我無法找到任何裝飾的名字「PropDecoratorFactory」,我看在app.module.ts沒有這樣decleration:


          
  
import { BrowserModule } from '@angular/platform-browser'; 
 
    import { NgModule } from '@angular/core'; 
 
    import { FormsModule } from '@angular/forms'; 
 
    import { HttpModule } from '@angular/http'; 
 
    import { Input } from '@angular/core'; 
 
    import { ViewChild } from '@angular/core'; 
 
    import { Output } from '@angular/core'; 
 
    import { AppComponent } from './app.component'; 
 
    import { HeaderComponent } from './header/header.component'; 
 
    import { PlayersBoardComponent } from './players-board/players-board.component'; 
 
    import { PlayerComponent } from './players-board/player/player.component'; 
 
    import { ScoresComponent } from './players-board/scores/scores.component'; 
 
    import { CopmPlayerComponent } from './players-board/copm-player/copm-player.component'; 
 

 
    @NgModule({ 
 
     declarations: [ 
 
     AppComponent, 
 
     HeaderComponent, 
 
     PlayersBoardComponent, 
 
     PlayerComponent, 
 
     ScoresComponent, 
 
     ], 
 
     imports: [ 
 
     BrowserModule, 
 
     FormsModule, 
 
     HttpModule, 
 
     ViewChild 
 
     ], 
 
     providers: [], 
 
     bootstrap: [AppComponent] 
 
    }) 
 
    export class AppModule { }

誰能告訴我是什麼問題?我能做些什麼來解決它? 謝謝

回答

0

您應從AppModule中的導入列表中移除ViewChild。

imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    ViewChild <--- Remove this one 
    ], 
+0

謝謝!輕鬆解決它 – mizenetofa1989

相關問題