简体   繁体   English

类型“ LocationComponent”是2个模块的声明的一部分:角6?

[英]Type “LocationComponent” is part of the declarations of 2 modules:Angular 6?

I am completely new to angular, so I cant able to resolve my error using other stack flow answers. 我对angular完全陌生,因此无法使用其他堆栈流程答案解决错误。 Kindly help. 请帮助。

I am using an angular 6. I already have a basic format,so I am trying to add child page. 我正在使用angular6。我已经有一种基本格式,因此我正在尝试添加子页面。 But I got this error 'Type LocationComponent is part of the declarations of 2 modules' and stuck in this for about 2 days. 但是我得到了这个错误“ Type LocationComponent是2个模块的声明的一部分”,并停留了大约2天。

Here is the picture of format of My src folder: 这是“我的src”文件夹格式的图片: 我的src文件夹:

My app.module.ts codings as follows: 我的app.module.ts编码如下:

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CommonModule, LocationStrategy, HashLocationStrategy } from '@angular/common';
import { NgModule, NgModuleFactory } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { Routes, RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LocationComponent } from './masterpage/location/location.component';
import { StorageComponent } from './masterpage/storage/storage.component';
@NgModule({
  declarations: [
    AppComponent,
    SpinnerComponent,         
    LocationComponent,
    StorageComponent
  ],
  imports: [
    CommonModule,
    BrowserModule,
    BrowserAnimationsModule,   
    FormsModule,
    HttpClientModule,
    NgbModule.forRoot(),      
    AppRoutingModule,        
  ],
  providers: [
      {
      provide: PERFECT_SCROLLBAR_CONFIG,
      useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
    },{
    provide: LocationStrategy,
    useClass: HashLocationStrategy
  }],
  bootstrap: [AppComponent]
})
export class AppModule { }

My app-routing.module.ts as follows: 我的app-routing.module.ts如下:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
export const routes: Routes = [
{
    path: '',
    component: FullComponent,
    children: [
        { path: '', redirectTo: '/masterpage/location', pathMatch: 'full' },
        { path: 'masterpage', loadChildren: './masterpage/masterpage.module#MasterPageModule' }, 
    ]
}];
@NgModule({
    imports: [RouterModule.forRoot(routes), NgbModule.forRoot()],
    exports: [RouterModule]
})
export class AppRoutingModule { }

My masterpage.module.ts codes as follows: 我的masterpage.module.ts代码如下:

import { NgModule,Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { LocationComponent } from './location/location.component';
import { StorageComponent } from './storage/storage.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { MasterPageRoutes } from './masterpage.routing';

@NgModule({
    imports: [
        FormsModule,
        CommonModule,
        NgbModule,
        RouterModule.forChild(MasterPageRoutes)
    ],
    declarations: [
        LocationComponent,
        StorageComponent,
    ]
})
export class MasterPageModule { }

My masterpage.routing.ts codes are below: 我的masterpage.routing.ts代码如下:

import { Routes } from '@angular/router';
import { LocationComponent } from './location/location.component';
import { StorageComponent } from './storage/storage.component';

export const MasterPageRoutes: Routes = [
  {
    path: '',
    children: [
    {
      path: 'location',
      component: LocationComponent,
      data: {
        title: 'Location',
        urls: [{title: 'Location',url: '/location'},{title: 'Location'}]
      }
    }, {
      path: 'storage',
      component: StorageComponent,
      data: {
        title: 'Storage',
        urls: [{title: 'Storage',url: '/storage'},{title: 'Storage'}]
      }
    }
]
  }
];

My Sample previously running with the url '/localhost:4200/#/dashboard/dashboard1' -this was the sample. 我的样本先前使用url '/ localhost:4200 /#/ dashboard / dashboard1'运行 -这是样本。 I changed the dashboard as per my request as 'masterpage' and its children 'dashboard1' and 'dashboard2' to 'location' and 'storage' respectively. 我按照自己的要求将仪表板更改为“母版页”,并将其子级“ dashboard1”和“ dashboard2”分别更改为“ location”和“ storage”。 I want the children pages location and storage must load with the url '/localhost:4200/#/masterpage/location' But its not working for me. 我希望子页面的位置和存储必须使用url '/ localhost:4200 /#/ masterpage / location'加载,但是它对我不起作用。 No error in code page. 代码页中没有错误。 Error I found out in console under inspect elements only. 我在控制台中仅在检查元素下发现错误。

Kindly help me what is wrong in it.. Thanks in Advance. 请帮我解决问题。.在此先感谢。

Since you've already declared LocationComponent in app.module.ts, it is already available app wide. 由于您已经在app.module.ts中声明了LocationComponent ,因此它已在整个应用范围内可用。 So, there is no need to declare it again in masterpage.module.ts . 因此,无需在masterpage.module.ts中再次声明它。

Remove LocationComponent in masterpage.module.ts from declarations array and also get rid of the imports. 从声明数组中删除masterpage.module.ts中的 LocationComponent ,并删除导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型Y是2个模块的声明的一部分-Angular 2 - Type Y is part of the declarations of 2 modules - Angular 2 组件是 Angular 中 2 个模块声明的一部分 - Component is part of the declarations of 2 modules in Angular 类型X是2个模块声明的一部分(Angular 2 RC5) - Type X is part of the declarations of 2 modules (Angular 2 RC5) 类型页面是 2 个模块错误声明的一部分 - Type page is part of the declarations of 2 modules error 角度错误:“是2个模块的声明的一部分(相同)” - Angular Error: “is part of the declarations of 2 modules (same)” Angular 7.2-“组件是2个模块的声明的一部分”,但不是 - Angular 7.2 - “component is part of the declarations of 2 modules” but it is not 类型 LeadPage(Module) 是 2 个模块声明的一部分 - Type LeadPage(Module) is part of the declarations of 2 modules 错误:类型组件是 2 个模块声明的一部分 - Error: Type Component is part of the declarations of 2 modules 角2:类型ChildComponent是以下两个模块的声明的一部分:parent1Module和Parent2Module - Angular 2 : Type ChildComponent is a part of the declarations of 2 modules : parent1Module and Parent2Module HMR 因 Angular 9 + IVY 失败:类型 AppComponent 是 2 个模块声明的一部分:AppModule 和 AppModule - HMR fails with Angular 9 + IVY: Type AppComponent is part of the declarations of 2 modules: AppModule and AppModule
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM