setItems added to ViewController

This commit is contained in:
Max Lynch
2015-06-20 12:54:18 -05:00
parent 2fdb4aeb29
commit 55e1817b0f
3 changed files with 39 additions and 11 deletions

View File

@ -4,8 +4,6 @@ import {Descendant} from 'angular2/src/core/annotations_impl/visibility';
import {View} from 'angular2/src/core/annotations_impl/view'; import {View} from 'angular2/src/core/annotations_impl/view';
import {Query} from 'angular2/src/core/annotations_impl/di'; import {Query} from 'angular2/src/core/annotations_impl/di';
console.log(Query, QueryList);
import {Ionic, Nav, ViewContainer, Aside, List, Item, Content} from 'ionic/ionic'; import {Ionic, Nav, ViewContainer, Aside, List, Item, Content} from 'ionic/ionic';
import {ButtonPage} from './pages/button' import {ButtonPage} from './pages/button'
@ -23,19 +21,17 @@ import {SlidePage} from './pages/slides'
import {ActionMenuPage} from './pages/action-menu' import {ActionMenuPage} from './pages/action-menu'
import {ModalPage} from './pages/modal' import {ModalPage} from './pages/modal'
console.log('Loaded', Nav, NgFor, NgIf, Aside, List, ViewContainer, Item, Content); console.log('Loaded', Nav, NgFor, NgIf, Aside, List, Item, Content);
@Component({ @Component({
selector: 'ion-view', selector: 'ion-view',
}) })
@View({ @View({
templateUrl: 'main.html', templateUrl: 'main.html',
directives: [Nav, NgFor, NgIf, Aside, List, ViewContainer, Item, Content] directives: [Nav, NgFor, NgIf, Aside, List, Item, Content]
}) })
class IonicApp { class IonicApp {
constructor(elementRef: ElementRef) {//, @Query(Aside) nav: QueryList) {//, @Descendant() aside: Aside) { constructor(elementRef: ElementRef) {//, @Query(Aside) nav: QueryList) {//, @Descendant() aside: Aside) {
Ionic.setRootElementRef(elementRef);
this.components = [ this.components = [
{ title: 'Navigation', component: NavPage }, { title: 'Navigation', component: NavPage },
{ title: 'Buttons', component: ButtonPage }, { title: 'Buttons', component: ButtonPage },
@ -58,11 +54,8 @@ class IonicApp {
openPage(aside, component) { openPage(aside, component) {
aside.close(); aside.close();
window.nav.clear().then(() => {
window.nav.push(component.component, {}, { window.nav.setItems([component.component]);
animate: false
});
})
} }
} }

View File

@ -5,6 +5,13 @@ export class NavController {
this._nav = nav; this._nav = nav;
} }
/**
* Set the history stack to match the list of component items.
*/
setItems(items) {
return this._nav.setItems(items);
}
/** /**
* Clear the history stack. * Clear the history stack.
*/ */

View File

@ -417,6 +417,34 @@ export class ViewController {
return this.items.length; return this.items.length;
} }
/**
* Set the item stack to reflect the given component classes.
*/
setItems(components) {
// Pop all of the current items
this.clear();
// Then, change the root
let leavingItem = this.getActive() || new ViewItem();
leavingItem.shouldDestroy = true;
leavingItem.shouldCache = false;
leavingItem.willUnload();
this.transitionComplete();
for(let c of components) {
this.push(c, {
animate: false
})
}
}
/**
* Pops off all the trailing items, but leaves the root.
* To change the root, call setRoot with the root component.
*/
clear() { clear() {
let pops = []; let pops = [];
for (let item of this.items) { for (let item of this.items) {