未捕获的错误:意外的值' PropDecoratorFactory'由模块' AppModule'导入。请添加@NgModule注释

时间:2017-07-06 10:24:55

标签: angular import module decorator

我正在构建一个简单的AngularJS 2 / s应用程序,并尝试将嵌套子组件中的变量传递给父组件,因此父级可以更改它,如下所示:

子:

    @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() {
      }

    }

父:

    @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() {
      }

    }

我的IDE说没有探测器,但是当我尝试运行整个应用程序时,我得到了这个错误消息:

    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() {
      }

    }

奇怪的是我无法找到任何装饰者名称" PropDecoratorFactory",我在app.module.ts中看不到这样的声音:

    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() {
      }

    }

谁能告诉我这是什么问题?我该怎么办才能修复它? 感谢

1 个答案:

答案 0 :(得分:0)

您应从AppModule中的导入列表中删除ViewChild。

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