module.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /**
  2. * Import Angular
  3. */
  4. import { ANALYZE_FOR_ENTRY_COMPONENTS, APP_INITIALIZER, ComponentFactoryResolver, Inject, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core';
  5. import { APP_BASE_HREF, HashLocationStrategy, Location, LocationStrategy, PathLocationStrategy, PlatformLocation } from '@angular/common';
  6. import { DOCUMENT, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
  7. import { FormsModule, ReactiveFormsModule } from '@angular/forms';
  8. import { CommonModule } from '@angular/common';
  9. /**
  10. * Import Other
  11. */
  12. import { DeepLinkConfig } from './navigation/nav-util';
  13. /**
  14. * Global Providers
  15. */
  16. import { App } from './components/app/app';
  17. import { AppRootToken } from './components/app/app-root';
  18. import { Config, ConfigToken, setupConfig } from './config/config';
  19. import { DeepLinker, setupDeepLinker } from './navigation/deep-linker';
  20. import { DomController } from './platform/dom-controller';
  21. import { Events, setupProvideEvents } from './util/events';
  22. import { Form } from './util/form';
  23. import { GestureController } from './gestures/gesture-controller';
  24. import { IonicGestureConfig } from './gestures/gesture-config';
  25. import { Haptic } from './tap-click/haptic';
  26. import { Keyboard } from './platform/keyboard';
  27. import { LAZY_LOADED_TOKEN, ModuleLoader, provideModuleLoader, setupPreloading } from './util/module-loader';
  28. import { NgModuleLoader } from './util/ng-module-loader';
  29. import { Platform, setupPlatform } from './platform/platform';
  30. import { PlatformConfigToken, providePlatformConfigs } from './platform/platform-registry';
  31. import { TapClick, setupTapClick } from './tap-click/tap-click';
  32. import { registerModeConfigs } from './config/mode-registry';
  33. import { TransitionController } from './transitions/transition-controller';
  34. import { DeepLinkConfigToken, UrlSerializer, setupUrlSerializer } from './navigation/url-serializer';
  35. /**
  36. * Import Components/Directives/Etc
  37. */
  38. import { ActionSheetCmp } from './components/action-sheet/action-sheet-component';
  39. import { ActionSheetController } from './components/action-sheet/action-sheet-controller';
  40. import { AlertCmp } from './components/alert/alert-component';
  41. import { AlertController } from './components/alert/alert-controller';
  42. import { ClickBlock } from './components/app/click-block';
  43. import { IonicApp } from './components/app/app-root';
  44. import { OverlayPortal } from './components/app/overlay-portal';
  45. import { Avatar } from './components/avatar/avatar';
  46. import { Backdrop } from './components/backdrop/backdrop';
  47. import { Badge } from './components/badge/badge';
  48. import { Button } from './components/button/button';
  49. import { Card } from './components/card/card';
  50. import { CardContent } from './components/card/card-content';
  51. import { CardHeader } from './components/card/card-header';
  52. import { CardTitle } from './components/card/card-title';
  53. import { Checkbox } from './components/checkbox/checkbox';
  54. import { Chip } from './components/chip/chip';
  55. import { Content } from './components/content/content';
  56. import { DateTime } from './components/datetime/datetime';
  57. import { FabButton } from './components/fab/fab';
  58. import { FabContainer } from './components/fab/fab-container';
  59. import { FabList } from './components/fab/fab-list';
  60. import { Col } from './components/grid/col';
  61. import { Grid } from './components/grid/grid';
  62. import { Row } from './components/grid/row';
  63. import { Icon } from './components/icon/icon';
  64. import { Img } from './components/img/img';
  65. import { InfiniteScroll } from './components/infinite-scroll/infinite-scroll';
  66. import { InfiniteScrollContent } from './components/infinite-scroll/infinite-scroll-content';
  67. import { TextInput } from './components/input/input';
  68. import { Item } from './components/item/item';
  69. import { ItemContent } from './components/item/item-content';
  70. import { ItemDivider } from './components/item/item-divider';
  71. import { ItemGroup } from './components/item/item-group';
  72. import { ItemOptions } from './components/item/item-options';
  73. import { ItemReorder } from './components/item/item-reorder';
  74. import { ItemSliding } from './components/item/item-sliding';
  75. import { Reorder } from './components/item/reorder';
  76. import { Label } from './components/label/label';
  77. import { List } from './components/list/list';
  78. import { ListHeader } from './components/list/list-header';
  79. import { LoadingCmp } from './components/loading/loading-component';
  80. import { LoadingController } from './components/loading/loading-controller';
  81. import { Menu } from './components/menu/menu';
  82. import { MenuClose } from './components/menu/menu-close';
  83. import { MenuController } from './components/app/menu-controller';
  84. import { MenuToggle } from './components/menu/menu-toggle';
  85. import { ModalCmp } from './components/modal/modal-component';
  86. import { ModalController } from './components/modal/modal-controller';
  87. import { Nav } from './components/nav/nav';
  88. import { NavPop } from './components/nav/nav-pop';
  89. import { NavPopAnchor } from './components/nav/nav-pop-anchor';
  90. import { NavPush } from './components/nav/nav-push';
  91. import { NavPushAnchor } from './components/nav/nav-push-anchor';
  92. import { Note } from './components/note/note';
  93. import { Option } from './components/option/option';
  94. import { PickerCmp } from './components/picker/picker-component';
  95. import { PickerColumnCmp } from './components/picker/picker-column';
  96. import { PickerController } from './components/picker/picker-controller';
  97. import { PopoverCmp } from './components/popover/popover-component';
  98. import { PopoverController } from './components/popover/popover-controller';
  99. import { RadioButton } from './components/radio/radio-button';
  100. import { RadioGroup } from './components/radio/radio-group';
  101. import { Range } from './components/range/range';
  102. import { RangeKnob } from './components/range/range-knob';
  103. import { Refresher } from './components/refresher/refresher';
  104. import { RefresherContent } from './components/refresher/refresher-content';
  105. import { Scroll } from './components/scroll/scroll';
  106. import { Searchbar } from './components/searchbar/searchbar';
  107. import { Segment } from './components/segment/segment';
  108. import { Select } from './components/select/select';
  109. import { SelectPopover } from './components/select/select-popover-component';
  110. import { SegmentButton } from './components/segment/segment-button';
  111. import { ShowWhen } from './components/show-hide-when/show-when';
  112. import { HideWhen } from './components/show-hide-when/hide-when';
  113. import { Slide } from './components/slides/slide';
  114. import { Slides } from './components/slides/slides';
  115. import { Spinner } from './components/spinner/spinner';
  116. import { SplitPane } from './components/split-pane/split-pane';
  117. import { Tab } from './components/tabs/tab';
  118. import { TabButton } from './components/tabs/tab-button';
  119. import { TabHighlight } from './components/tabs/tab-highlight';
  120. import { Tabs } from './components/tabs/tabs';
  121. import { Thumbnail } from './components/thumbnail/thumbnail';
  122. import { ToastCmp } from './components/toast/toast-component';
  123. import { ToastController } from './components/toast/toast-controller';
  124. import { Toggle } from './components/toggle/toggle';
  125. import { Footer } from './components/toolbar/toolbar-footer';
  126. import { Header } from './components/toolbar/toolbar-header';
  127. import { Toolbar } from './components/toolbar/toolbar';
  128. import { ToolbarItem } from './components/toolbar/toolbar-item';
  129. import { ToolbarTitle } from './components/toolbar/toolbar-title';
  130. import { Navbar } from './components/toolbar/navbar';
  131. import { Typography } from './components/typography/typography';
  132. import { VirtualFooter } from './components/virtual-scroll/virtual-footer';
  133. import { VirtualHeader } from './components/virtual-scroll/virtual-header';
  134. import { VirtualItem } from './components/virtual-scroll/virtual-item';
  135. import { VirtualScroll } from './components/virtual-scroll/virtual-scroll';
  136. /**
  137. * @name IonicModule
  138. * @description
  139. * IonicModule is an [NgModule](https://angular.io/docs/ts/latest/guide/ngmodule.html) that bootstraps
  140. * an Ionic App. By passing a root component, IonicModule will make sure that all of the components,
  141. * directives, and providers from the framework are imported.
  142. *
  143. * Any configuration for the app can be passed as the second argument to `forRoot`. This can be any
  144. * valid property from the [Config](/docs/api/config/Config/).
  145. *
  146. * @usage
  147. * ```ts
  148. * import { NgModule } from '@angular/core';
  149. *
  150. * import { IonicApp, IonicModule } from 'ionic-angular';
  151. *
  152. * import { MyApp } from './app.component';
  153. * import { HomePage } from '../pages/home/home';
  154. *
  155. * @NgModule({
  156. * declarations: [
  157. * MyApp,
  158. * HomePage
  159. * ],
  160. * imports: [
  161. * BrowserModule,
  162. * IonicModule.forRoot(MyApp, {
  163. *
  164. * })
  165. * ],
  166. * bootstrap: [IonicApp],
  167. * entryComponents: [
  168. * MyApp,
  169. * HomePage
  170. * ],
  171. * providers: []
  172. * })
  173. * export class AppModule {}
  174. * ```
  175. */
  176. @NgModule({
  177. declarations: [
  178. ActionSheetCmp,
  179. AlertCmp,
  180. ClickBlock,
  181. IonicApp,
  182. OverlayPortal,
  183. Avatar,
  184. Backdrop,
  185. Badge,
  186. Button,
  187. Card,
  188. CardContent,
  189. CardHeader,
  190. CardTitle,
  191. Checkbox,
  192. Chip,
  193. Col,
  194. Content,
  195. DateTime,
  196. FabButton,
  197. FabContainer,
  198. FabList,
  199. Grid,
  200. Img,
  201. Icon,
  202. InfiniteScroll,
  203. InfiniteScrollContent,
  204. Item,
  205. ItemContent,
  206. ItemDivider,
  207. ItemGroup,
  208. ItemOptions,
  209. ItemReorder,
  210. ItemSliding,
  211. Label,
  212. List,
  213. ListHeader,
  214. Reorder,
  215. LoadingCmp,
  216. Menu,
  217. MenuClose,
  218. MenuToggle,
  219. ModalCmp,
  220. Nav,
  221. NavPop,
  222. NavPopAnchor,
  223. NavPush,
  224. NavPushAnchor,
  225. Note,
  226. Option,
  227. PickerCmp,
  228. PickerColumnCmp,
  229. PopoverCmp,
  230. RadioButton,
  231. RadioGroup,
  232. Range,
  233. RangeKnob,
  234. Refresher,
  235. RefresherContent,
  236. Row,
  237. Scroll,
  238. Searchbar,
  239. Segment,
  240. SegmentButton,
  241. Select,
  242. SelectPopover,
  243. ShowWhen,
  244. HideWhen,
  245. Slide,
  246. Slides,
  247. Spinner,
  248. SplitPane,
  249. Tab,
  250. TabButton,
  251. TabHighlight,
  252. Tabs,
  253. TextInput,
  254. Thumbnail,
  255. ToastCmp,
  256. Toggle,
  257. Footer,
  258. Header,
  259. Toolbar,
  260. ToolbarItem,
  261. ToolbarTitle,
  262. Navbar,
  263. Typography,
  264. VirtualFooter,
  265. VirtualHeader,
  266. VirtualItem,
  267. VirtualScroll
  268. ],
  269. imports: [
  270. CommonModule,
  271. FormsModule,
  272. ReactiveFormsModule,
  273. ],
  274. exports: [
  275. CommonModule,
  276. FormsModule,
  277. ReactiveFormsModule,
  278. ActionSheetCmp,
  279. AlertCmp,
  280. ClickBlock,
  281. IonicApp,
  282. OverlayPortal,
  283. Avatar,
  284. Backdrop,
  285. Badge,
  286. Button,
  287. Card,
  288. CardContent,
  289. CardHeader,
  290. CardTitle,
  291. Checkbox,
  292. Chip,
  293. Col,
  294. Content,
  295. DateTime,
  296. FabButton,
  297. FabContainer,
  298. FabList,
  299. Grid,
  300. Img,
  301. Icon,
  302. InfiniteScroll,
  303. InfiniteScrollContent,
  304. Item,
  305. ItemContent,
  306. ItemDivider,
  307. ItemGroup,
  308. ItemOptions,
  309. ItemReorder,
  310. ItemSliding,
  311. Label,
  312. List,
  313. ListHeader,
  314. Reorder,
  315. LoadingCmp,
  316. Menu,
  317. MenuClose,
  318. MenuToggle,
  319. ModalCmp,
  320. Nav,
  321. NavPop,
  322. NavPopAnchor,
  323. NavPush,
  324. NavPushAnchor,
  325. Note,
  326. Option,
  327. PickerCmp,
  328. PickerColumnCmp,
  329. PopoverCmp,
  330. RadioButton,
  331. RadioGroup,
  332. Range,
  333. RangeKnob,
  334. Refresher,
  335. RefresherContent,
  336. Row,
  337. Scroll,
  338. Searchbar,
  339. Segment,
  340. SegmentButton,
  341. Select,
  342. SelectPopover,
  343. ShowWhen,
  344. HideWhen,
  345. Slide,
  346. Slides,
  347. Spinner,
  348. SplitPane,
  349. Tab,
  350. TabButton,
  351. TabHighlight,
  352. Tabs,
  353. TextInput,
  354. Thumbnail,
  355. ToastCmp,
  356. Toggle,
  357. Footer,
  358. Header,
  359. Toolbar,
  360. ToolbarItem,
  361. ToolbarTitle,
  362. Navbar,
  363. Typography,
  364. VirtualFooter,
  365. VirtualHeader,
  366. VirtualItem,
  367. VirtualScroll
  368. ],
  369. entryComponents: [
  370. ActionSheetCmp,
  371. AlertCmp,
  372. IonicApp,
  373. LoadingCmp,
  374. ModalCmp,
  375. PickerCmp,
  376. PopoverCmp,
  377. SelectPopover,
  378. ToastCmp
  379. ]
  380. })
  381. export class IonicModule {
  382. /**
  383. * Set the root app component for you IonicModule
  384. * @param {any} appRoot The root AppComponent for this app.
  385. * @param {any} config Config Options for the app. Accepts any config property.
  386. * @param {any} deepLinkConfig Any configuration needed for the Ionic Deeplinker.
  387. */
  388. static forRoot(appRoot: any, config: any = null, deepLinkConfig: DeepLinkConfig = null): ModuleWithProviders {
  389. return {
  390. ngModule: IonicModule,
  391. providers: [
  392. // useValue: bootstrap values
  393. { provide: AppRootToken, useValue: appRoot },
  394. { provide: ConfigToken, useValue: config },
  395. { provide: DeepLinkConfigToken, useValue: deepLinkConfig },
  396. { provide: APP_BASE_HREF, useValue: '/'},
  397. // useFactory: user values
  398. { provide: PlatformConfigToken, useFactory: providePlatformConfigs },
  399. // useFactory: ionic core providers
  400. { provide: Platform, useFactory: setupPlatform, deps: [ DOCUMENT, PlatformConfigToken, NgZone ] },
  401. { provide: Config, useFactory: setupConfig, deps: [ ConfigToken, Platform ] },
  402. // useFactory: ionic app initializers
  403. { provide: APP_INITIALIZER, useFactory: registerModeConfigs, deps: [ Config ], multi: true },
  404. { provide: APP_INITIALIZER, useFactory: setupProvideEvents, deps: [ Platform, DomController ], multi: true },
  405. { provide: APP_INITIALIZER, useFactory: setupTapClick, deps: [ Config, Platform, DomController, App, GestureController ], multi: true },
  406. { provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ Config, DeepLinkConfigToken, ModuleLoader, NgZone ], multi: true },
  407. // useClass
  408. { provide: HAMMER_GESTURE_CONFIG, useClass: IonicGestureConfig },
  409. // useValue
  410. { provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: appRoot, multi: true },
  411. // ionic providers
  412. ActionSheetController,
  413. AlertController,
  414. App,
  415. DomController,
  416. Events,
  417. Form,
  418. GestureController,
  419. Haptic,
  420. Keyboard,
  421. LoadingController,
  422. Location,
  423. MenuController,
  424. ModalController,
  425. NgModuleLoader,
  426. PickerController,
  427. PopoverController,
  428. TapClick,
  429. ToastController,
  430. TransitionController,
  431. { provide: ModuleLoader, useFactory: provideModuleLoader, deps: [NgModuleLoader, Injector]},
  432. { provide: LocationStrategy, useFactory: provideLocationStrategy, deps: [ PlatformLocation, [new Inject(APP_BASE_HREF), new Optional()], Config ] },
  433. { provide: UrlSerializer, useFactory: setupUrlSerializer, deps: [ App, DeepLinkConfigToken ] },
  434. { provide: DeepLinker, useFactory: setupDeepLinker, deps: [ App, UrlSerializer, Location, ModuleLoader, ComponentFactoryResolver ] },
  435. ]
  436. };
  437. }
  438. }
  439. /**
  440. * @name IonicPageModule
  441. * @description
  442. * IonicPageModule is an [NgModule](https://angular.io/docs/ts/latest/guide/ngmodule.html) that
  443. * bootstraps a child [IonicPage](../navigation/IonicPage/) in order to set up routing.
  444. *
  445. * @usage
  446. * ```ts
  447. * import { NgModule } from '@angular/core';
  448. *
  449. * import { IonicPageModule } from 'ionic-angular';
  450. *
  451. * import { HomePage } from './home';
  452. *
  453. * @NgModule({
  454. * declarations: [
  455. * HomePage
  456. * ],
  457. * imports: [
  458. * IonicPageModule.forChild(HomePage)
  459. * ],
  460. * entryComponents: [
  461. * HomePage
  462. * ]
  463. * })
  464. * export class HomePageModule { }
  465. * ```
  466. */
  467. @NgModule({
  468. imports: [IonicModule],
  469. exports: [IonicModule]
  470. })
  471. export class IonicPageModule {
  472. static forChild(page: any): ModuleWithProviders {
  473. return {
  474. ngModule: IonicPageModule,
  475. providers: [
  476. { provide: <any>LAZY_LOADED_TOKEN, useValue: page },
  477. { provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: page, multi: true },
  478. ]
  479. };
  480. }
  481. }
  482. /**
  483. * @hidden
  484. */
  485. export function provideLocationStrategy(platformLocationStrategy: PlatformLocation,
  486. baseHref: string, config: Config) {
  487. return config.get('locationStrategy') === 'path' ?
  488. new PathLocationStrategy(platformLocationStrategy, baseHref) :
  489. new HashLocationStrategy(platformLocationStrategy, baseHref);
  490. }