123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. import { Component, ComponentFactoryResolver, ElementRef, ErrorHandler, Input, NgZone, Optional, Renderer, ViewChild, ViewContainerRef, ViewEncapsulation, forwardRef } from '@angular/core';
  12. import { App } from '../app/app';
  13. import { Config } from '../../config/config';
  14. import { DeepLinker } from '../../navigation/deep-linker';
  15. import { DomController } from '../../platform/dom-controller';
  16. import { GestureController } from '../../gestures/gesture-controller';
  17. import { NavController } from '../../navigation/nav-controller';
  18. import { NavControllerBase } from '../../navigation/nav-controller-base';
  19. import { Platform } from '../../platform/platform';
  20. import { TransitionController } from '../../transitions/transition-controller';
  21. import { ViewController } from '../../navigation/view-controller';
  22. import { RootNode } from '../split-pane/split-pane';
  23. /**
  24. * @name Nav
  25. * @description
  26. *
  27. * `ion-nav` is the declarative component for a [NavController](../../../navigation/NavController/).
  28. *
  29. * For more information on using nav controllers like Nav or [Tab](../../Tabs/Tab/),
  30. * take a look at the [NavController API Docs](../../../navigation/NavController/).
  31. *
  32. *
  33. * @usage
  34. * You must set a root page to be loaded initially by any Nav you create, using
  35. * the 'root' property:
  36. *
  37. * ```ts
  38. * import { Component } from '@angular/core';
  39. * import { GettingStartedPage } from './getting-started';
  40. *
  41. * @Component({
  42. * template: `<ion-nav [root]="root"></ion-nav>`
  43. * })
  44. * class MyApp {
  45. * root = GettingStartedPage;
  46. *
  47. * constructor(){
  48. * }
  49. * }
  50. * ```
  51. *
  52. * @demo /docs/demos/src/navigation/
  53. * @see {@link /docs/components#navigation Navigation Component Docs}
  54. */
  55. var Nav = (function (_super) {
  56. __extends(Nav, _super);
  57. function Nav(viewCtrl, parent, app, config, plt, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, domCtrl, errHandler) {
  58. var _this = _super.call(this, parent, app, config, plt, elementRef, zone, renderer, cfr, gestureCtrl, transCtrl, linker, domCtrl, errHandler) || this;
  59. _this._hasInit = false;
  60. if (viewCtrl) {
  61. // an ion-nav can also act as an ion-page within a parent ion-nav
  62. // this would happen when an ion-nav nests a child ion-nav.
  63. viewCtrl._setContent(_this);
  64. }
  65. if (parent) {
  66. // this Nav has a parent Nav
  67. parent.registerChildNav(_this);
  68. }
  69. else if (viewCtrl && viewCtrl.getNav()) {
  70. // this Nav was opened from a modal
  71. _this.parent = viewCtrl.getNav();
  72. _this.parent.registerChildNav(_this);
  73. }
  74. else if (app && !app.getRootNavById(_this.id)) {
  75. // a root nav has not been registered yet with the app
  76. // this is the root navcontroller for the entire app
  77. app.registerRootNav(_this);
  78. }
  79. return _this;
  80. }
  81. Object.defineProperty(Nav.prototype, "_vp", {
  82. /**
  83. * @hidden
  84. */
  85. set: function (val) {
  86. this.setViewport(val);
  87. },
  88. enumerable: true,
  89. configurable: true
  90. });
  91. Nav.prototype.ngAfterViewInit = function () {
  92. var _this = this;
  93. this._hasInit = true;
  94. var segment = this._linker.getSegmentByNavIdOrName(this.id, this.name);
  95. if (segment && (segment.component || segment.loadChildren)) {
  96. return this._linker.initViews(segment).then(function (views) {
  97. return _this.setPages(views, null, null);
  98. });
  99. }
  100. else if (this._root) {
  101. // no segment match, so use the root property but don't set the url I guess
  102. var setUrl = segment ? false : true;
  103. return this.push(this._root, this.rootParams, {
  104. isNavRoot: (this._app.getRootNavById(this.id) === this),
  105. updateUrl: setUrl
  106. }, null);
  107. }
  108. };
  109. Object.defineProperty(Nav.prototype, "root", {
  110. /**
  111. * @input {Page} The Page component to load as the root page within this nav.
  112. */
  113. get: function () {
  114. return this._root;
  115. },
  116. set: function (page) {
  117. this._root = page;
  118. if (this._hasInit) {
  119. this.setRoot(page);
  120. }
  121. },
  122. enumerable: true,
  123. configurable: true
  124. });
  125. /**
  126. * @hidden
  127. */
  128. Nav.prototype.ngOnDestroy = function () {
  129. this.destroy();
  130. };
  131. Nav.prototype.initPane = function () {
  132. var isMain = this._elementRef.nativeElement.hasAttribute('main');
  133. return isMain;
  134. };
  135. Nav.prototype.paneChanged = function (isPane) {
  136. if (isPane) {
  137. this.resize();
  138. }
  139. };
  140. Nav.prototype.goToRoot = function (opts) {
  141. return this.setRoot(this._root, this.rootParams, opts, null);
  142. };
  143. /*
  144. * @private
  145. */
  146. Nav.prototype.getType = function () {
  147. return 'nav';
  148. };
  149. /*
  150. * @private
  151. */
  152. Nav.prototype.getSecondaryIdentifier = function () {
  153. return null;
  154. };
  155. Nav.decorators = [
  156. { type: Component, args: [{
  157. selector: 'ion-nav',
  158. template: '<div #viewport nav-viewport></div>' +
  159. '<div class="nav-decor"></div>',
  160. encapsulation: ViewEncapsulation.None,
  161. providers: [{ provide: RootNode, useExisting: forwardRef(function () { return Nav; }) }]
  162. },] },
  163. ];
  164. /** @nocollapse */
  165. Nav.ctorParameters = function () { return [
  166. { type: ViewController, decorators: [{ type: Optional },] },
  167. { type: NavController, decorators: [{ type: Optional },] },
  168. { type: App, },
  169. { type: Config, },
  170. { type: Platform, },
  171. { type: ElementRef, },
  172. { type: NgZone, },
  173. { type: Renderer, },
  174. { type: ComponentFactoryResolver, },
  175. { type: GestureController, },
  176. { type: TransitionController, },
  177. { type: DeepLinker, decorators: [{ type: Optional },] },
  178. { type: DomController, },
  179. { type: ErrorHandler, },
  180. ]; };
  181. Nav.propDecorators = {
  182. '_vp': [{ type: ViewChild, args: ['viewport', { read: ViewContainerRef },] },],
  183. 'root': [{ type: Input },],
  184. 'rootParams': [{ type: Input },],
  185. 'name': [{ type: Input },],
  186. };
  187. return Nav;
  188. }(NavControllerBase));
  189. export { Nav };
  190. //# sourceMappingURL=nav.js.map