2017-11-30 29 views
1

ダイアログをAngularモジュールに統合しようとしていますが、 IDE:角度エラー: 'コンポーネント' X 'はモジュールに含まれていません...'サブモジュールで宣言されたとき

私の知る限りでは、コンポーネント(パイプとディレクティブのみ)を他のモジュールで使用するためにエクスポートする必要はありません。

このエラーが発生しても、アプリケーションはまだ読み込まれて正常に実行されます。

例コンポーネント定義

import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core'; 
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; 

export interface AlertDialogData { 
    titleText: string; 
    dismissalText: string; 
    contentComponent: string; 
} 

@Component({ 
    selector: 'app-alert-dialog', 
    templateUrl: './alert-dialog.component.html', 
    styleUrls: ['./alert-dialog.component.scss'], 
    encapsulation: ViewEncapsulation.None 
}) 
export class AlertDialogComponent implements OnInit { 

    constructor(private dialogRef: MatDialogRef<AlertDialogComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { } 

    ngOnInit() { 
    } 

    handleCloseClick(): void { 
    this.dialogRef.close(); 
    } 

} 

サブモジュール宣言/エクスポートを行う

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { ZipLocatorDialogComponent } from './zip-locator-dialog/zip-locator-dialog.component'; 
import { AlertDialogComponent } from './alert-dialog/alert-dialog.component'; 
import { HelperDialogComponent } from './helper-dialog/helper-dialog.component'; 
import { 
    MatAutocompleteModule, MatButtonModule, MatDialogModule, MatFormFieldModule, MatInputModule, 
    MatSelectModule 
} from '@angular/material'; 
import { FlexLayoutModule } from '@angular/flex-layout'; 
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 

@NgModule({ 
    imports: [ 
    CommonModule, 
    FlexLayoutModule, 
    FormsModule, 
    ReactiveFormsModule, 
    MatDialogModule, 
    MatInputModule, 
    MatFormFieldModule, 
    MatSelectModule, 
    MatAutocompleteModule, 
    MatButtonModule 
    ], 
    exports: [ 
    ZipLocatorDialogComponent, 
    HelperDialogComponent, 
    AlertDialogComponent 
    ], 
    declarations: [ 
    ZipLocatorDialogComponent, 
    HelperDialogComponent, 
    AlertDialogComponent 
    ], 
    entryComponents: [ 
    ZipLocatorDialogComponent, 
    HelperDialogComponent, 
    AlertDialogComponent 
    ], 
    schemas: [ 
    CUSTOM_ELEMENTS_SCHEMA 
    ] 
}) 
export class AppDialogsModule { } 

アプリケーションモジュール

// <editor-fold desc="Global Application Imports"> 
import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; 
import { RouterModule } from '@angular/router'; 
import { RouteDefinitions } from './app.routes'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
import { FlexLayoutModule } from '@angular/flex-layout'; 
import { WebWrapperModule } from 'web-wrapper'; 
import { UiComponentsModule } from './ui-components.module'; 
import { AppComponent } from './app.component'; 


// OPERATORS 
import './rxjs-operators'; 

// SERVICES 
import { LoginManagerService } from './services/login-manager.service'; 
import { UtilsService } from './services/utils.service'; 
import { DataManagerService } from './services/data-manager.service'; 
import { ReferenceDataManagerService } from './services/reference-data-manager.service'; 
import { InfrastructureApiService } from './services/infrastructure-api.service'; 
// </editor-fold> 

@NgModule({ 
    declarations: [ 
    AppComponent 
    ], 
    imports: [ 
    BrowserModule, 
    BrowserAnimationsModule, 
    FormsModule, 
    FlexLayoutModule, 
    HttpClientModule, 
    WebWrapperModule, 
    UiComponentsModule, 
    AppDialogsModule, 
    RouterModule.forRoot(RouteDefinitions) 
    ], 
    providers: [ 
    UtilsService, 
    LoginManagerService, 
    DataManagerService, 
    InfrastructureApiService, 
    ReferenceDataManagerService 
    ], 
    schemas: [ 
    CUSTOM_ELEMENTS_SCHEMA 
    ], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

バージョン

Angular CLI: 1.5.0 
Node: 7.2.1 
OS: win32 x64 
Angular: 4.4.6 
... animations, common, compiler, compiler-cli, core, forms 
... http, language-service, platform-browser 
... platform-browser-dynamic, router, tsc-wrapped 

@angular/cdk: 2.0.0-beta.12 
@angular/cli: 1.5.0 
@angular/flex-layout: 2.0.0-beta.11-b01c2d7 
@angular/material: 2.0.0-beta.12 
@angular-devkit/build-optimizer: 0.0.32 
@angular-devkit/core: 0.0.20 
@angular-devkit/schematics: 0.0.35 
@ngtools/json-schema: 1.1.0 
@ngtools/webpack: 1.8.0 
@schematics/angular: 0.1.2 
typescript: 2.4.2 
webpack: 3.8.1 
+0

エラーメッセージに文字どおり「x」と表示されますか?または、あなたのコンポーネントの1つの名前?また、提供されたコードのように、共有モジュールの各コンポーネントをエクスポートしているようですか?また、共有したいモジュールをすべてエクスポートする予定ですか? – DeborahK

+0

文字通り 'X'ではなく、 'AppDialogsModule'で宣言されたすべてのダイアログコンポーネント、つまり' HelperDialogComponent'に表示されます。輸出は唯一含まれている、私はそれが別のSOの答えで提供されて見たので、それは違いはありません。 'AppDialogsModule'は' AppModule'へのインポートとして既に含まれています。 – rawkfist0215

+1

これはどのように動作するかについてのいくつかのルールがあります。 https://www.youtube.com/watch?v=ntJ-P-Cvo7o&t=1s – DeborahK

答えて

1

まず:宣言セクション(AppModule)にすべてのコンポーネントを宣言します。

問題が解決しない場合は、beta angular-cliのバージョンに問題があることを覚えています。

The issue you are running into is a variant of the baseUrl issue. The language service does not correctly respect the baseUrl option. For example, if you change the import of the shared module from app/shared/shared.module to ../shared/shared.module then the errors go away.

+0

このようにすると、次のエラーが発生します。 'Uncaught Error:タイプZipLocatorDialogComponentは、2つのモジュールの宣言の一部です:AppDialogsModuleとAppModule! ZipLocatorDialogComponentをAppDialogsModuleとAppModuleをインポートする上位モジュールに移動することを検討してください。ZipLocatorDialogComponentをエクスポートしてインクルードする新しいNgModuleを作成し、そのNgModuleをAppDialogsModuleとAppModuleにインポートすることもできます。これは、最初から何をしようとしているのかをまとめたものです。 – rawkfist0215

+0

** imports **から削除し、このモジュールのみを**宣言** – alvaropanizo

+0

に入れてください。残念ですが、エラーメッセージは表示されます。 Angularはアプリをコンパイルして例外なく実行するので、混乱しているのはlintingツールだけです。 – rawkfist0215

関連する問題