更新角度到rc5后,我有一个小问题。
我开始将我的应用程序重写为模块[ngModules]。
我有一个小问题,我有两个不同的模块,但是module1需要从其他模块调用指令(组件)。
现在我这样做了,但是没用...
AppModule(模块1):
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HttpModule } from '@angular/http';
import { SimCardsModule } from './+sim-cards/sim-cards.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
CommonModule,
FormsModule,
HttpModule,
SimCardsModule
],
providers: [],
entryComponents: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {
}
AppComponent:
import { Component } from '@angular/core';
declare let $: any;
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css']
})
export class AppComponent {
}
并在模板中
<sim-cards> loading </sim-cards>
现在我有sim-cards.module(模块2):
import { NgModule, ApplicationRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { SimCardsComponent } from './sim-cards.component';
import { SimCardsService } from './sim-cards.service';
@NgModule({
declarations: [
SimCardsComponent
],
imports: [
CommonModule,
FormsModule,
HttpModule
],
providers: [SimCardsService],
entryComponents: [SimCardsComponent],
bootstrap: [SimCardsComponent]
})
export class SimCardsModule {
}
和sim-cards.component(模块2):
import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {SimCardsService} from './sim-cards.service';
import {IfEmptySetDefaultPipe} from '../pipes/if-empty-set-default.pipe';
import {IsInternalSimCardPipe} from '../pipes/is-internal-sim-card.pipe';
import {ClientNumberSimCardPipe} from '../pipes/client-number-sim-card.pipe';
import {OperatorIdSimCardPipe} from '../pipes/operator-id-sim-card.pipe';
declare let $: any;
@Component({
selector: 'sim-cards',
templateUrl: 'sim-cards.component.html',
styleUrls: ['sim-cards.component.scss'],
encapsulation: ViewEncapsulation.None,
pipes: [IfEmptySetDefaultPipe, IsInternalSimCardPipe, ClientNumberSimCardPipe, OperatorIdSimCardPipe]
})
export class SimCardsComponent implements OnInit {
...
}
如何以正确的方式做到这一点?我是否需要在appmodule中导入组件(SIM卡)?在appcomponent中?
或者我做错了什么??
在浏览器中,我只得到字符串,正在加载...在控制台中没有错误。
SimCardsComponent
从SimCardsModule导出。在导入模块中只能使用导出的组件。
@NgModule({
exports: [SimCardsComponent],
...
})
export class SimCardsModule {
该NgModule文档是必读的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句