Hello how is it possible to call a variable from different .ts file in different page inside src code???
For example, i am getting a webapi token from a httppost request in home page and i have a loginPage in which i want to use the webapi token in order to make authentication user.
wow it seemed very awesome
but i am getting this error when i am insterting in my constructor
constructor(
public navCtrl: NavController, public navParams: NavParams,
private loginserviceprovider: LoginserviceProvider,
public other:HomePage) {
}
Looks like you’re trying to get the token from the homepage, but you should probably be getting it from the login service provider, e.g. via loginserviceprovider.getWebApi() etc.
import {LoginserviceProvider} from "../../providers/loginservice/loginservice";
export class CurrentComponent {
token:string;
constructor(
private loginserviceprovider: LoginserviceProvider,
) { }
this.token = loginserviceprovider.SomeFunctionFromProviderThatReturnsToken()
If the getWebApi function returns the token (as the code above implies if I’m reading it correctly), you can use it to set a persistent variable and then create a new function that returns it as needed.
Then you can use loginserviceprovider.getReturnedToken() in your other pages. You might need to make use of promises to ensure that the default null value isn’t returned.
There is virtually always a categorically better approach than a timeout with a magic number. Refactor your provider to provide Observables of business objects and react to them. Your app will be both more reliable and more efficient.
But i think is very general answer and my code (which i didnt upload) is very specific.
What do you mean by Observables of business objects?
Let me show you my code files.
By “business object” I mean things like the (currently anonymous) type of paramsScroller. HttpClient is an internal implementation detail, not something going over the wire, so I don’t see how the getXXX functions make sense. There are examples of using HttpClienthere that you should be able to adapt to your situation.
A rule I always try to follow is to never mix production and consumption of Observables in the same function (or generally even in the same class). So I would get rid of all the subscriptions in your provider and instead subscribe to Observables returned by the public provider methods in your pages. That should let you get rid of all the timeouts safely and reliably.
My app post and get params,requests from a Webservice.
I receive a webtoken from Webservice and in order to get more Jsons and schrollers from the webservice i use the same webtoken as a param.
Also I made a Loginscreen where EndUser has to input his credentials and store them inside storage.
Storage should make an authentication between the credentials in a JSON which exists in Webservice and the credentials that the user typed.
If they match login screen disappears.
After this whole process ,application should remember the credentials and never call the login screen again
Maybe my thought to have all my “post,request http code” inside the provider is wrong…
But i can’t find any other practical way how to get rid from subscriptions and Observables for posting and getting requests…
Every single example in the web uses this way…
The only way to get rid of all these stupid Time-outs is to seperate my subscribes from Observables?or
Not use them at all?