Rx subscribe - different behaviour in chrome and native ios app

Revisiting previously working code with ionic2beta, now with ionic3.

I have this code pice, where mapObject is a Leaflet Marker object.

mapObject.controller = this; //assigns view controller to map object so that view controller would be available in onClick function
    //this is now the marker
    this.controller._stationService.getStationData(this.name).subscribe(report =>{
          //this is now not clearly defined. With ionic2 beta, it used to be the still the marker. Still works in Chrome but breaks in native iOS app 

Running ionic serve and testing with Chrome, this will remain the same mapObject / marker as in the outside scope that called getStationData.

Running the code as an App on iOS, in the inside scope this is a different object. It does not have the controller attribute anymore, hence the whole bracket fails.

Now, what really puzzles me is that it used to work before, still works in Chrome but fails in iOS…

What shall I try?

In ionic, you 99.99% of the time never need to nor should type function. (Particularly within one)

Instead, when you would type:

() =>

1 Like

Never again typing the word “function”. Use arrow functions or lambdas.

1 Like

Ok, I will add () => {} , but now how do I get the map object that was selected by the user?
Should it be

mapObject.onClick((clickedMarker) => { 
    this // still my main view controller
    clickedMarker //the object I want


Yes, I should refactor the code wherever possible…

@rapropos @SigmundFroyd

Ok, I replaced it with

mapObject.onClick((clickedObject) => {
    const clickedMarker = clickedObject.target; //not sure why it's convoluted and I have to unwrap this
    //this is the view controller - good
    this._stationService.getStationData(this.name).subscribe(report =>{
          //this is now a 
          SafeSubscriber {closed: false, _parent: null, _parents: null, _subscriptions: null, syncErrorValue: null, …}
          //not the view controller


So, what is SafeSubscriber , how did it get here and how can I get rid of it?
SafeSubscriber {closed: false, _parent: null, _parents: null, _subscriptions: null, syncErrorValue: null, …}