Angular 2 - 无法解析组件的所有参数

时间:2017-06-27 09:12:05

标签: angular angular2-routing angular2-services angular2-components

在修改了一些文件结构后,我的共享通信组件出错了。

  

compiler.es5.js:1540未捕获错误:无法解析所有参数   CommunicatesComponent:(?)。       在syntaxError(http://localhost:4200/vendor.bundle.js:60570:34)       在CompileMetadataResolver._getDependenciesMetadata(http://localhost:4200/vendor.bundle.js:73907:35)       在CompileMetadataResolver._getTypeMetadata(http://localhost:4200/vendor.bundle.js:73775:26)       在CompileMetadataResolver.getNonNormalizedDirectiveMetadata(http://localhost:4200/vendor.bundle.js:73384:24)       在CompileMetadataResolver._loadDirectiveMetadata(http://localhost:4200/vendor.bundle.js:73242:25)       在http://localhost:4200/vendor.bundle.js:73471:54       at Array.forEach(native)       在CompileMetadataResolver.loadNgModuleDirectiveAndPipeMetadata(http://localhost:4200/vendor.bundle.js:73470:41)       在http://localhost:4200/vendor.bundle.js:84666:58       在Array.forEach(native)

文件结构:

app
-- app.module.ts
-- shared/
---- shared.module.ts
---- communicates/
------ communicates.component.ts
------ communicates.service.ts
-- core/
-- feature/
---- feature.module.ts
---- feature.component.ts
---- feature.template.html
-- app.component.ts
-- app.template.html

communicates.component.ts

import { Component, ViewChild, OnInit, ViewEncapsulation } from '@angular/core';
import { CommunicatesService } from './communicates.service'
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import 'rxjs/add/operator/share';


import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';

@Component({
    selector: 'communicates-popover',
    styleUrls: [ 'communicates.css' ],
    encapsulation: ViewEncapsulation.None,
    templateUrl: './communicates.template.html',
    providers: []
})
export class CommunicatesComponent implements OnInit {
    //Communicates objects
    public communicates:Communicate [] = [];

    //Popover 
    @ViewChild('communicatePopover') private communicatePopover: NgbPopover;

    constructor(private communicatesService:CommunicatesService) {         
    }
...rest of code
}

shared.module.ts

import { NgModule }      from '@angular/core';
import { CommonModule }  from '@angular/common'
import { RouterModule, Routes } from '@angular/router';
import { HttpModule } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'

import { CommunicatesService } from './communicates/communicates.service'
import { CommunicatesComponent } from './communicates/communicates.component'

@NgModule({
    imports:      [ 
                    BrowserAnimationsModule,
                    FormsModule, 
                    CommonModule,
                   // BrowserModule,
                    ReactiveFormsModule,                                        
                    HttpModule ],
    declarations: [ 
                    CommunicatesComponent
                    ],
    providers:    [CommunicatesService],
    exports: [               
                CommunicatesComponent                
            ],
})
export class SharedModule { }
当我包含shared.module

时,

和app.module

import { NgModule }      from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module'
import { CoreModule } from './core/core.module'

const appRoutes: Routes = [
    { path: 'feature', loadChildren: './feature/feature.module#FeatureModule' }
];
@NgModule({
    imports:      [ RouterModule.forRoot(appRoutes), 
                    SharedModule, 
                    CoreModule],
    declarations: [ AppComponent ],
    providers:    [],
    bootstrap:    [ AppComponent ],
    entryComponents: []
})
export class AppModule { }

此致

0 个答案:

没有答案