在Angular2中,可以通过使用@NgModule
装饰器将导入从父模块继承到子模块。@NgModule
装饰器用于定义一个模块,并且可以指定该模块所依赖的其他模块。
要将导入从父模块继承到子模块,可以在子模块的@NgModule
装饰器中使用imports
属性,并将父模块作为其值之一。这样子模块就可以继承父模块中导入的所有模块。
以下是一个示例:
// 父模块
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from '../shared/shared.module';
@NgModule({
imports: [
CommonModule,
SharedModule
],
declarations: [
// 父模块的组件和指令
],
exports: [
// 父模块导出的组件和指令
]
})
export class ParentModule { }
// 子模块
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ParentModule } from '../parent/parent.module';
@NgModule({
imports: [
CommonModule,
ParentModule
],
declarations: [
// 子模块的组件和指令
],
exports: [
// 子模块导出的组件和指令
]
})
export class ChildModule { }
在上面的示例中,子模块通过将父模块添加到imports
数组中,继承了父模块中导入的所有模块。这样子模块就可以使用父模块中定义的组件、指令和其他功能。
推荐的腾讯云相关产品和产品介绍链接地址:
请注意,以上仅为示例推荐,实际选择云计算产品应根据具体需求和情况进行评估和决策。
领取专属 10元无门槛券
手把手带您无忧上云