Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229654

Random Page Select

$
0
0

Please help, I have tried to setup the random page selector from what rapropos suggested but have got stuck with the below error:

Close
Typescript Error
Cannot find name 'Subject'.
src/pages/home/home.ts
wheel = new Subject();

The code I used is shown below - I tried looking up the offending line:
wheel = new Subject(); in home.ts file but could not work out what was wrong. I am new to this so any help would be appreciated.

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-home-page',
  templateUrl: 'home.html',

})
export class RandomPageService {

  constructor(public navCtrl: NavController, public navParams: NavParams, private rps: RandomPageService) {
  }

 wheel = new Subject<string>();

  spin(): void {
    let page = 'mcw' + Math.floor(Math.random()*54).toString();
    this.wheel.next(page);
  }

  onQuickReadNowButtonClicked(): void {
    this.rps.spin();
  }

  //navigateToReadnowPage() {
  //  this.navCtrl.push('mcw6');
  //}
  openIssue1() {
    this.navCtrl.push('Issue1Page');
  }
  openIssue2() {
    this.navCtrl.push('Issue2Page');
  }
  openIssue3() {
    this.navCtrl.push('Issue3Page');
  }
  openIssue4() {
    this.navCtrl.push('Issue4Page');
  }
}

The associated code in home.module.ts is:

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { RandomPageService } from './home';

@NgModule({
  declarations: [
    RandomPageService,
  ],
  imports: [
    IonicPageModule.forChild(RandomPageService),
  ],
  exports: [
    RandomPageService
  ]
})
export class RandomPageServiceModule {}

And app.components.ts:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { RandomPageService } from '../pages/home/home';

@Component({
  templateUrl: 'app.html'
})


export class MyApp {
  rootPage:any = 'TabsPage';

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, rps: RandomPageService) {
    rps.wheel.subscribe(pn=> this.rootPage = pn);
    platform.ready().then(() => {
     statusBar.styleDefault();
      splashScreen.hide();
    });
  }
}

Viewing all articles
Browse latest Browse all 229654

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>