简体   繁体   English

Angular2-在路由中在每个模块上导入插件?

[英]Angular2 - import addons on each module… in routing?

Do I must import for example: "import { Angular2FontawesomeModule } from 'angular2-fontawesome/angular2-fontawesome'" , import { MaterialModule } from '@angular/material'; 我是否必须导入例如: "import { Angular2FontawesomeModule } from 'angular2-fontawesome/angular2-fontawesome'"import { MaterialModule } from '@angular/material'; ... for both module? ...两个模块? (home.module.ts and app.module.ts) (home.module.ts和app.module.ts)

if I wanna use this in my login and dashborad Component? 如果我想在我的登录名和dashborad组件中使用它?

becouse I have error like "Unhandled Promise rejection: Template parse errors: Can't bind to 'name' since it isn't a known property of 'fa'...." 因为我遇到类似“未处理的承诺拒绝:模板解析错误:由于它不是'fa'的已知属性而无法绑定到'name'的错误。”

-app
  -login
    *login.component.html
    ...
  -home
    -dasborad
      *dashboard.component.html
      ...
    -users
      *user.component.html
      ...
    *home.component.html
    *home.component
    *home.module
  -toolbar
    *toolbar.component.html
  *app.component
  *app.module

app.module app.module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HttpModule, BaseRequestOptions, Http } from '@angular/http';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Angular2FontawesomeModule } from 'angular2-fontawesome/angular2-fontawesome'
import { MaterialModule } from '@angular/material';
import { FlexLayoutModule } from '@angular/flex-layout';
import { ResponsiveModule } from 'ng2-responsive'
import 'hammerjs';

import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { LoginViewComponent } from './login/login-view.component';

import { HomeModule } from "./home/home.module"

const appRoutes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'login', component: LoginComponent },
  { path: '**', component: LoginComponent }
];

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    LoginViewComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    Angular2FontawesomeModule,
    MaterialModule,
    FlexLayoutModule,
    ResponsiveModule,

    RouterModule.forRoot(appRoutes),
    HomeModule
  ],
  exports: [ RouterModule ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

home.module home.module

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

import { HomeComponent } from './home.component';
import { TopToolbarComponent } from '../toolbar/toolbar.component';

import { DashboardComponent } from './dashboard/dashboard.component';
import { UserComponent } from './user/user.component';


export const homeRoutes: Routes = [
    {
        path: 'home',
        component: HomeComponent,
        children:[
            { path: '', component: DashboardComponent },
            { path: 'dashboard', pathMatch: 'full', component: DashboardComponent },
            { path: 'user', pathMatch: 'full', component: UserComponent }
        ]
    }
]

@NgModule({
    imports: [
        RouterModule.forChild(homeRoutes)
    ],
    exports: [ 
        RouterModule 
    ],
    declarations: [ 
        TopToolbarComponent, 
        TopSearchComponent,
        HomeComponent,

        DashboardComponent,
        UserComponent
    ]
})

export class HomeModule{}

You can create a common/shared module with all these common imports, after this just import this shared module to every module (in Imports array) where you want the same functionality. 您可以使用所有这些公共导入创建一个公共/共享模块,然后将共享模块导入到您想要相同功能的每个模块(在Imports数组中)。 Please refer to this link . 请参考此链接

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM