ionic2+ 基础
ionic2+ 基础
一 项目入口
1.index.html
<ion-app></ion-app>
2.main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; //设置AppModule为引导模块 platformBrowserDynamic().bootstrapModule(AppModule);
3. app.module.ts
imports: [ IonicModule.forRoot(MyApp) ], bootstrap: [IonicApp]
4. app.components.ts
@Component({ templateUrl: 'app.html' }) export class MyApp {}
二 定义模块&组件
组件定义
import { Component } from '@angular/core'; @Component({ templateUrl: 'home-page.html' }) export class HomePage { constructor() { } }
service 定义
import {Injectable} from "@angular/core"; //声明为可注入服务 单例 @Injectable() export class HomeService { constructor() { } }
模块定义
import { NgModule } from '@angular/core'; import { IonicModule } from 'ionic-angular'; import { HomePage } from './home.page' import { HomeService } from './home.service' @NgModule({ //引入其他模块 imports: [ IonicModule ], //声明组件 declarations: [ HomePage ], //导出组件标签 exports:[ ], //导出组件类 entryComponents: [ HomePage ], //导出服务 providers: [ HomeService ] }) export class HomeModule {}
主模块引用其他模块
import { NgModule, ErrorHandler } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; import { MyApp } from './app.component'; import { TabsPage } from './tabs/tabs'; //引入自定义模块 import { HomeModule } from './home/home.module'; @NgModule({ declarations: [ MyApp, TabsPage ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), //导入自定义模块 HomeModule ], bootstrap: [IonicApp], entryComponents: [ MyApp, TabsPage ], providers: [ StatusBar, SplashScreen, {provide: ErrorHandler, useClass: IonicErrorHandler} ] }) export class AppModule {}
相关推荐
nickking 2016-12-03
shiyiboke 2017-09-01
芯果科技蔡彦 2016-11-21
前端开发探路者 2016-11-21
genglang 2018-08-17
半纸药笺 2019-06-28
templateUrl:'build/app.html',<ion-navid="nav"[root]="rootPage"#contentswipe-back-enabled="false"
codewhile 2016-03-24
庆华 2019-06-26
nickking 2019-06-25
samllcat 2019-06-25
samllcat 2019-06-25
庆华 2019-06-25
nickking 2019-06-25
nickking 2019-06-25
庆华 2019-06-21
rimuweinuan 2019-06-21
chenxiangpeng 2019-06-21
rimuweinuan 2019-06-20
samllcat 2019-06-20