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



我正在构建一个简单的 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() {
}
}

家长:


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说没有探测器,但是当我尝试运行整个应用程序时,我收到以下错误消息:

> 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中没有看到这样的降级:


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

谁能告诉我问题是什么?我能做些什么来修复它? 谢谢

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

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

相关内容

  • 没有找到相关文章

最新更新