[angular2] [ngModules]如何从其他模块调用组件?
发布时间:2020-12-17 09:27:39 所属栏目:安全 来源:网络整理
导读:更新角度到rc5后我有一个小问题. 我开始将我的应用程序重新编写为模块[ngModules]. 我有一个小问题,我有两个不同的模块,但module1需要从其他模块调用一个指令(组件). 现在我这样做,但没有奏效…… AppModule(模块1): import { BrowserModule } from '@angul
更新角度到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,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? 或者我做错了什么? 在浏览器中我只得到字符串,加载…在控制台中没有错误.
从SimCardsModule导出SimCardsComponent.只有导出的组件才可用于导入模块.
@NgModule({ exports: [SimCardsComponent],... }) export class SimCardsModule { NgModule documentation是必读的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |