11import { Component } from '@angular/core' ;
22import { NavController , NavParams , IonicPage } from 'ionic-angular' ;
33
4- import { Topic } from './topic' ;
4+ import { Topic } from '../../classes /topic' ;
55
66import { TopicService } from '../../providers/topic-service' ;
77
@@ -13,12 +13,13 @@ import { TopicService } from '../../providers/topic-service';
1313*/
1414
1515@IonicPage ( {
16- name : 'topics'
16+ name : 'topics' ,
17+ segment : 'topics/:tab'
1718} )
1819@Component ( {
1920 selector : 'page-topics' ,
2021 templateUrl : 'topics.html' ,
21- providers : [ TopicService ]
22+ providers : [ TopicService ]
2223} )
2324export class TopicsPage {
2425
@@ -28,31 +29,39 @@ export class TopicsPage {
2829 constructor ( public navCtrl : NavController , public navParams : NavParams , private topicService : TopicService ) {
2930 }
3031
31- ngOnInit ( ) : void {
32- this . getTopics ( )
33- }
32+ ngOnInit ( ) : void {
33+ let newTab = this . navParams . get ( 'tab' ) ;
34+ if ( newTab ) {
35+ console . log ( 'changing tab' ) ;
36+ this . topicService . currentTab = newTab ;
37+ }
38+ console . log ( 'current tab' , this . topicService . currentTab ) ;
39+ this . doRefresh ( ) ;
40+ }
3441
3542 ionViewDidLoad ( ) {
3643 console . log ( 'ionViewDidLoad TopicsPage' ) ;
3744 }
3845
39- onSelect ( topic : Topic ) : void {
40- console . log ( topic )
41- this . navCtrl . push ( 'topic' , { id : topic . id } )
42- }
46+ onSelect ( topic : Topic ) : void {
47+ console . log ( topic )
48+ this . navCtrl . push ( 'topic' , { id : topic . id } )
49+ }
4350
44- getTopics ( ) : void {
45- this . topicService . getTopics ( ) . then (
46- topics => this . topics = topics
47- ) ;
48- }
51+ getTopics ( ) : void {
52+ this . topicService . getTopics ( ) . then (
53+ topics => this . topics = topics
54+ ) ;
55+ }
4956
50- doRefresh ( refresher ) : void {
57+ doRefresh ( refresher = undefined ) : void {
5158 console . log ( 'do refresh' )
5259 this . topicService . refresh ( ) . then (
5360 ( topics ) => {
5461 this . topics = topics ;
55- refresher . complete ( ) ;
62+ if ( refresher ) {
63+ refresher . complete ( ) ;
64+ }
5665 }
5766 ) ;
5867 }
0 commit comments