I just tried the Loading component, and I´m getting
browser_adapter.ts:73 TypeError: Cannot read property 'nativeElement' of undefined
at new LoadingMdPopOut (http://localhost:8100/build/js/app.bundle.js:48166:40)
at Function.Transition.createTransition (http://localhost:8100/build/js/app.bundle.js:68127:16)
at http://localhost:8100/build/js/app.bundle.js:50623:58
at ZoneDelegate.invoke (http://localhost:8100/build/js/angular2-polyfills.js:390:29)
at Zone.run (http://localhost:8100/build/js/angular2-polyfills.js:283:44)
at NgZoneImpl.runOuter (http://localhost:8100/build/js/app.bundle.js:29001:71)
at NgZone.runOutsideAngular (http://localhost:8100/build/js/app.bundle.js:28919:80)
at Portal.NavController._beforeTrans (http://localhost:8100/build/js/app.bundle.js:50613:20)
at Portal.NavController._postRender (http://localhost:8100/build/js/app.bundle.js:50595:14)
at Portal.NavController._render (http://localhost:8100/build/js/app.bundle.js:50511:18)
------------- Elapsed: 74 ms; At: Tue Apr 26 2016 16:58:57 GMT-0300 (ART) -------------
at Object.Zone.longStackTraceZoneSpec.onScheduleTask (http://localhost:8100/build/js/angular2-polyfills.js:1413:23)```
Hi, thanks it works when using in Component directly. But if I want to intercept in service Http - it shows: Cannot read property ‘create’ of undefined. So it is stopping on let loader = this.loadingController.create({
content: “your message”
});
loader.present();
I am extending Http with my custom HttpService, where in Appmodule I also implement:
Services should not be interacting with the view layer. Don’t try to interact with a LoadingController from a service. I also think it’s better to wrap Http using composition instead of inheritance.
Ok I understand. Thanks. So what would be recommended way to “not to repeat” every time LoaderController creation code? But to attach to every http request?
That’s a pretty open-ended question that’s hard to answer in a general way. Sometimes I want it to be done as the page is becoming active, sometimes I want it as part of an explicit refresh action, sometimes I just don’t care to present it to the user and just let network activity happen in the background. There are a lot of different situations in which you might want to present a loading spinner, and it probably won’t always be the same in all your pages, which is another reason to get it out of the service.
@fathermonkey: if you dismiss a loading object, it’s destroyed. Presenting it back will result in an error (the error you mentioned earlier).
It’s better to create the loading object each time you need it :
Instead of
this.loading.present();
This is my component.ts
import { Component } from ‘@angular/core’;
import { NavController, NavParams } from ‘ionic-angular’;
import {Deneme} from ‘…/…/providers/deneme’;
import { Http,Response } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
import { LoadingController } from ‘ionic-angular’;
Hi, I am very much new to ionic2 can you please explain what is this
…/…/providers/data-service/data-service? what type of providers you use means exactly what we have to place in providers folder and how you get this data-service? Or can you share your full project with all this folders.