ionic3.x - 建立组件 (component)

1 、cd 到咱们的项目目录
2 、经过 ionic g component 组件名称建立组件
app

3 、建立完成组件之后会在 src 目录下面多一个 components 的目录,这个目录里面有我
们用命令建立的全部的组件
ionic

ionic 建立组件后,components 文件夹下的组件会以一个自定义模块方式加载,在 component.modules.ts 中spa

import { NgModule } from '@angular/core';
import { ActionsheetComponent } from './actionsheet/actionsheet';
//引入BrowserModule  解决 ngFor报错的问题
import { BrowserModule } from '@angular/platform-browser';
import { UserlistComponent } from './userlist/userlist';
@NgModule({
    declarations: [ActionsheetComponent,
    UserlistComponent],
    imports: [BrowserModule],  /*依赖注入*/
    exports: [ActionsheetComponent,
    UserlistComponent/* 导出组件 */
})
export class ComponentsModule {}

若是咱们要使用这些组件必须在 app.module.ts 里面注册咱们的模块- component.modules,注册完成后就可
在 以在 pages 里面的其页面里面使用这些组件
component

//引入components模块
import { ComponentsModule } from '../components/components.module';
@NgModule({
  declarations: [   /*申明组件*/
    MyApp,
    AboutPage,
    ContactPage,
    HomePage,
    TabsPage
  ],
  imports: [  /*引入的模块 依赖的模块*/
    BrowserModule,
    ComponentsModule,
    IonicModule.forRoot(MyApp)
  ],

在组件中使用 angular 的 *ngFor 会报错,如何解决?orm

解决: 在component.module.ts 中引入 BrowserModule it

//引入BrowserModule  解决 ngFor报错的问题
import { BrowserModule } from '@angular/platform-browser';
相关文章
相关标签/搜索