在之前的文章中有提到项目的源码全部存放在项目根目录的src文件夹,我们之后所有的代码开发也是在该目录进行
image.png

app文件夹

app.component.ts 根组件

  1. import { Component } from '@angular/core';
  2. import { Platform } from 'ionic-angular';
  3. import { StatusBar } from '@ionic-native/status-bar';
  4. import { SplashScreen } from '@ionic-native/splash-screen';
  5. import { TabsPage } from '../pages/tabs/tabs';
  6. @Component({
  7. templateUrl: 'app.html'
  8. })
  9. export class MyApp {
  10. rootPage:any = TabsPage;
  11. constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
  12. platform.ready().then(() => {
  13. // Okay, so the platform is ready and our plugins are available.
  14. // Here you can do any higher level native things you might need.
  15. statusBar.styleDefault();
  16. splashScreen.hide();
  17. });
  18. }
  19. }

平时所说的视图,主要定义了app整体的视觉表现,比如根页面、状态栏、启动界面等等。

app.html APP的根界面

  1. <ion-nav [root]="rootPage"></ion-nav>

相当于Android的MainActivity界面显示的内容

app.module.ts 根模块文件

  1. import { NgModule, ErrorHandler } from '@angular/core';
  2. import { BrowserModule } from '@angular/platform-browser';
  3. import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
  4. import { MyApp } from './app.component';
  5. import { AboutPage } from '../pages/about/about';
  6. import { ContactPage } from '../pages/contact/contact';
  7. import { HomePage } from '../pages/home/home';
  8. import { TabsPage } from '../pages/tabs/tabs';
  9. import { StatusBar } from '@ionic-native/status-bar';
  10. import { SplashScreen } from '@ionic-native/splash-screen';
  11. @NgModule({
  12. declarations: [
  13. MyApp,
  14. AboutPage,
  15. ContactPage,
  16. HomePage,
  17. TabsPage
  18. ],
  19. imports: [
  20. BrowserModule,
  21. IonicModule.forRoot(MyApp)
  22. ],
  23. bootstrap: [IonicApp],
  24. entryComponents: [
  25. MyApp,
  26. AboutPage,
  27. ContactPage,
  28. HomePage,
  29. TabsPage
  30. ],
  31. providers: [
  32. StatusBar,
  33. SplashScreen,
  34. {provide: ErrorHandler, useClass: IonicErrorHandler}
  35. ]
  36. })
  37. export class AppModule {}

ionic是基于angular的,而angular是完全模块化的。配置项目中使用到的模块、组件、服务、管道、指令等

app.scss

全局样式文件

main.ts

入口文件

  1. import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
  2. import { AppModule } from './app.module';
  3. platformBrowserDynamic().bootstrapModule(AppModule);

在最初接触到网页开发时,都是用到一个js,就在HTML中增加一个标签,现在只需要调用入口文件,然后由入口文件去引入其它依赖的文件。

assets文件夹

存放项目中使用到的各种资源

pages文件夹

存放APP中用到的所有界面,其下的一个文件夹就是独立的一个界面
image.png
每一个界面文件夹下存放三个文件,分别是界面、模板样式和业务处理逻辑(用TypeScript—-JavaScript的超级 语法编写)

theme文件夹

APP主题样式文件