Ionic 3: Ionic Storage with ObservablesHandling refresh tokens using rxjsWhat is the difference between Promises and Observables?BehaviorSubject vs Observable?Generic build request method response undefinedIonic Storage service with observablesRead object field from observable using async pipeAngular/Ionic passing API key in headerHTTP GET cannot read property 'length' when passing a header into the request in ionic 3Combine 3 streams with Observables in series and in parallelCannot display the name parameter of product in dropdown select
How to remove the first colon ':' from a timestamp?
What is the meaning of [[:space:]] in bash?
A Table Representing the altar
How possible is a successful landing just with 1 wing?
Kepler space telescope undetected planets
Is there an English equivalent for "Les carottes sont cuites", while keeping the vegetable reference?
Generating a PIN from cryptographic bytes
Random piece of plastic
Cauchy reals and Dedekind reals satisfy "the same mathematical theorems"
Does the Intel 8085 CPU use real memory addresses?
what relax command means?
Why is Katakana not pronounced Katagana?
Why doesn't philosophy have higher standards for its arguments?
Wordplay subtraction paradox
My credit card has no magnetic stripe. Is this a problem in the USA?
What are the basics of commands in Minecraft Java Edition?
How can a drink contain 1.8 kcal energy while 0 g fat/carbs/protein?
Is this artwork (used in a video game) real?
What would be the safest way to drop thousands of small, hard objects from a typical, high wing, GA airplane?
Is it legal for a supermarket to refuse to sell an adult beer if an adult with them doesn’t have their ID?
Is there a typesafe way to get a Database.QueryLocator?
Why is the total probability theorem expressed in this way?
Finding all possible pairs of square numbers in an array
Is this Android phone Android 9.0 or Android 6.0?
Ionic 3: Ionic Storage with Observables
Handling refresh tokens using rxjsWhat is the difference between Promises and Observables?BehaviorSubject vs Observable?Generic build request method response undefinedIonic Storage service with observablesRead object field from observable using async pipeAngular/Ionic passing API key in headerHTTP GET cannot read property 'length' when passing a header into the request in ionic 3Combine 3 streams with Observables in series and in parallelCannot display the name parameter of product in dropdown select
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have CustomerPage, CustomerService and AuthService.
In need to pass an access_token from AuthService to CustomerService for http-get request.
AuthService and CustomerService are not working.
Please help me!
Thnx.
CustomerPage:
this.customerService.getCustomersDashboard()
.subscribe(....)
CustomerService:
getCustomersDashboard(): Observable<any> {
var url = "......";
let authHeader = this.authservice.getAuthHeaders(); // HttpHeader with access_token
return this.http.get(url, headers: authHeader ).pipe(
map((resp: Response) =>
let response = this.extractData(resp);
return response;
));
AuthService:
is not working !!!
getAuthHeaders()
const authtoken = Observable.fromPromise(this.storage.get(`access_token`));
return new HttpHeaders( 'authorization': authtoken ); // => **not working**
angular ionic-framework rxjs
add a comment |
I have CustomerPage, CustomerService and AuthService.
In need to pass an access_token from AuthService to CustomerService for http-get request.
AuthService and CustomerService are not working.
Please help me!
Thnx.
CustomerPage:
this.customerService.getCustomersDashboard()
.subscribe(....)
CustomerService:
getCustomersDashboard(): Observable<any> {
var url = "......";
let authHeader = this.authservice.getAuthHeaders(); // HttpHeader with access_token
return this.http.get(url, headers: authHeader ).pipe(
map((resp: Response) =>
let response = this.extractData(resp);
return response;
));
AuthService:
is not working !!!
getAuthHeaders()
const authtoken = Observable.fromPromise(this.storage.get(`access_token`));
return new HttpHeaders( 'authorization': authtoken ); // => **not working**
angular ionic-framework rxjs
Is your storage API promise based? If it is async -- you can't just pass it to the headers. UseswitchMap
to read value from the storage and switch to the http-get. If it is sync -- then you dont need afromPromise
there.
– kos
Mar 26 at 10:02
Ionic storage is promise based ! Can you provide pseudo-code with switchMap? Thnx
– Alexander
Mar 26 at 14:32
add a comment |
I have CustomerPage, CustomerService and AuthService.
In need to pass an access_token from AuthService to CustomerService for http-get request.
AuthService and CustomerService are not working.
Please help me!
Thnx.
CustomerPage:
this.customerService.getCustomersDashboard()
.subscribe(....)
CustomerService:
getCustomersDashboard(): Observable<any> {
var url = "......";
let authHeader = this.authservice.getAuthHeaders(); // HttpHeader with access_token
return this.http.get(url, headers: authHeader ).pipe(
map((resp: Response) =>
let response = this.extractData(resp);
return response;
));
AuthService:
is not working !!!
getAuthHeaders()
const authtoken = Observable.fromPromise(this.storage.get(`access_token`));
return new HttpHeaders( 'authorization': authtoken ); // => **not working**
angular ionic-framework rxjs
I have CustomerPage, CustomerService and AuthService.
In need to pass an access_token from AuthService to CustomerService for http-get request.
AuthService and CustomerService are not working.
Please help me!
Thnx.
CustomerPage:
this.customerService.getCustomersDashboard()
.subscribe(....)
CustomerService:
getCustomersDashboard(): Observable<any> {
var url = "......";
let authHeader = this.authservice.getAuthHeaders(); // HttpHeader with access_token
return this.http.get(url, headers: authHeader ).pipe(
map((resp: Response) =>
let response = this.extractData(resp);
return response;
));
AuthService:
is not working !!!
getAuthHeaders()
const authtoken = Observable.fromPromise(this.storage.get(`access_token`));
return new HttpHeaders( 'authorization': authtoken ); // => **not working**
angular ionic-framework rxjs
angular ionic-framework rxjs
asked Mar 26 at 9:10
AlexanderAlexander
82 bronze badges
82 bronze badges
Is your storage API promise based? If it is async -- you can't just pass it to the headers. UseswitchMap
to read value from the storage and switch to the http-get. If it is sync -- then you dont need afromPromise
there.
– kos
Mar 26 at 10:02
Ionic storage is promise based ! Can you provide pseudo-code with switchMap? Thnx
– Alexander
Mar 26 at 14:32
add a comment |
Is your storage API promise based? If it is async -- you can't just pass it to the headers. UseswitchMap
to read value from the storage and switch to the http-get. If it is sync -- then you dont need afromPromise
there.
– kos
Mar 26 at 10:02
Ionic storage is promise based ! Can you provide pseudo-code with switchMap? Thnx
– Alexander
Mar 26 at 14:32
Is your storage API promise based? If it is async -- you can't just pass it to the headers. Use
switchMap
to read value from the storage and switch to the http-get. If it is sync -- then you dont need a fromPromise
there.– kos
Mar 26 at 10:02
Is your storage API promise based? If it is async -- you can't just pass it to the headers. Use
switchMap
to read value from the storage and switch to the http-get. If it is sync -- then you dont need a fromPromise
there.– kos
Mar 26 at 10:02
Ionic storage is promise based ! Can you provide pseudo-code with switchMap? Thnx
– Alexander
Mar 26 at 14:32
Ionic storage is promise based ! Can you provide pseudo-code with switchMap? Thnx
– Alexander
Mar 26 at 14:32
add a comment |
2 Answers
2
active
oldest
votes
To read async data and then make a request with it — use a switchMap
operator
getCustomersDashboard()
const url = '//...';
// read data from storage
return from(this.storage.get('access_token')).pipe(
// now switch to a http-get request
switchMap(access_token =>
// make a HttpHeaders from it
const headers = new HttpHeaders( 'authorization': access_token );
return this.http.get(url, headers )
),
// here you'll have your request results
map(response =>
this.extractData(response)
)
)
Note that fromPromise
is now just from
.
Hope this helps
Not working, "The 'this' context of type 'void' is not assignable to methods 'this' of type 'Observable<>'
– Alexander
Mar 26 at 16:00
@Alexander, its hard to understand what this error indicates. What line it is?
– kos
Mar 26 at 16:06
all lines in switchMap
– Alexander
Mar 26 at 16:17
@Alexander, hmm, I'm not sure why TS might complain there (apart from my misspelling access_token). Could you create a stackblitz for this? Its was rather a pseudocode.
– kos
Mar 26 at 16:28
stackblitz.com/edit/ionic-w4tp3x
– Alexander
Mar 26 at 16:42
|
show 4 more comments
you can use this:
this.local.get('access_token');
or else you can use these methods:
for setting the token:
this.local = new Storage(LocalStorage);
this.local.set("YourTokenValue", this.access_token);
for Getting the token:
toCheckStatus();
function toCheckStatus()
self.local = new Storage(LocalStorage);
self.local.get('access_token').then((token) =>
console.log("token", token);
);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353362%2fionic-3-ionic-storage-with-observables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To read async data and then make a request with it — use a switchMap
operator
getCustomersDashboard()
const url = '//...';
// read data from storage
return from(this.storage.get('access_token')).pipe(
// now switch to a http-get request
switchMap(access_token =>
// make a HttpHeaders from it
const headers = new HttpHeaders( 'authorization': access_token );
return this.http.get(url, headers )
),
// here you'll have your request results
map(response =>
this.extractData(response)
)
)
Note that fromPromise
is now just from
.
Hope this helps
Not working, "The 'this' context of type 'void' is not assignable to methods 'this' of type 'Observable<>'
– Alexander
Mar 26 at 16:00
@Alexander, its hard to understand what this error indicates. What line it is?
– kos
Mar 26 at 16:06
all lines in switchMap
– Alexander
Mar 26 at 16:17
@Alexander, hmm, I'm not sure why TS might complain there (apart from my misspelling access_token). Could you create a stackblitz for this? Its was rather a pseudocode.
– kos
Mar 26 at 16:28
stackblitz.com/edit/ionic-w4tp3x
– Alexander
Mar 26 at 16:42
|
show 4 more comments
To read async data and then make a request with it — use a switchMap
operator
getCustomersDashboard()
const url = '//...';
// read data from storage
return from(this.storage.get('access_token')).pipe(
// now switch to a http-get request
switchMap(access_token =>
// make a HttpHeaders from it
const headers = new HttpHeaders( 'authorization': access_token );
return this.http.get(url, headers )
),
// here you'll have your request results
map(response =>
this.extractData(response)
)
)
Note that fromPromise
is now just from
.
Hope this helps
Not working, "The 'this' context of type 'void' is not assignable to methods 'this' of type 'Observable<>'
– Alexander
Mar 26 at 16:00
@Alexander, its hard to understand what this error indicates. What line it is?
– kos
Mar 26 at 16:06
all lines in switchMap
– Alexander
Mar 26 at 16:17
@Alexander, hmm, I'm not sure why TS might complain there (apart from my misspelling access_token). Could you create a stackblitz for this? Its was rather a pseudocode.
– kos
Mar 26 at 16:28
stackblitz.com/edit/ionic-w4tp3x
– Alexander
Mar 26 at 16:42
|
show 4 more comments
To read async data and then make a request with it — use a switchMap
operator
getCustomersDashboard()
const url = '//...';
// read data from storage
return from(this.storage.get('access_token')).pipe(
// now switch to a http-get request
switchMap(access_token =>
// make a HttpHeaders from it
const headers = new HttpHeaders( 'authorization': access_token );
return this.http.get(url, headers )
),
// here you'll have your request results
map(response =>
this.extractData(response)
)
)
Note that fromPromise
is now just from
.
Hope this helps
To read async data and then make a request with it — use a switchMap
operator
getCustomersDashboard()
const url = '//...';
// read data from storage
return from(this.storage.get('access_token')).pipe(
// now switch to a http-get request
switchMap(access_token =>
// make a HttpHeaders from it
const headers = new HttpHeaders( 'authorization': access_token );
return this.http.get(url, headers )
),
// here you'll have your request results
map(response =>
this.extractData(response)
)
)
Note that fromPromise
is now just from
.
Hope this helps
edited May 2 at 21:01
answered Mar 26 at 14:49
koskos
2,1111 gold badge5 silver badges17 bronze badges
2,1111 gold badge5 silver badges17 bronze badges
Not working, "The 'this' context of type 'void' is not assignable to methods 'this' of type 'Observable<>'
– Alexander
Mar 26 at 16:00
@Alexander, its hard to understand what this error indicates. What line it is?
– kos
Mar 26 at 16:06
all lines in switchMap
– Alexander
Mar 26 at 16:17
@Alexander, hmm, I'm not sure why TS might complain there (apart from my misspelling access_token). Could you create a stackblitz for this? Its was rather a pseudocode.
– kos
Mar 26 at 16:28
stackblitz.com/edit/ionic-w4tp3x
– Alexander
Mar 26 at 16:42
|
show 4 more comments
Not working, "The 'this' context of type 'void' is not assignable to methods 'this' of type 'Observable<>'
– Alexander
Mar 26 at 16:00
@Alexander, its hard to understand what this error indicates. What line it is?
– kos
Mar 26 at 16:06
all lines in switchMap
– Alexander
Mar 26 at 16:17
@Alexander, hmm, I'm not sure why TS might complain there (apart from my misspelling access_token). Could you create a stackblitz for this? Its was rather a pseudocode.
– kos
Mar 26 at 16:28
stackblitz.com/edit/ionic-w4tp3x
– Alexander
Mar 26 at 16:42
Not working, "The 'this' context of type 'void' is not assignable to methods 'this' of type 'Observable<>'
– Alexander
Mar 26 at 16:00
Not working, "The 'this' context of type 'void' is not assignable to methods 'this' of type 'Observable<>'
– Alexander
Mar 26 at 16:00
@Alexander, its hard to understand what this error indicates. What line it is?
– kos
Mar 26 at 16:06
@Alexander, its hard to understand what this error indicates. What line it is?
– kos
Mar 26 at 16:06
all lines in switchMap
– Alexander
Mar 26 at 16:17
all lines in switchMap
– Alexander
Mar 26 at 16:17
@Alexander, hmm, I'm not sure why TS might complain there (apart from my misspelling access_token). Could you create a stackblitz for this? Its was rather a pseudocode.
– kos
Mar 26 at 16:28
@Alexander, hmm, I'm not sure why TS might complain there (apart from my misspelling access_token). Could you create a stackblitz for this? Its was rather a pseudocode.
– kos
Mar 26 at 16:28
stackblitz.com/edit/ionic-w4tp3x
– Alexander
Mar 26 at 16:42
stackblitz.com/edit/ionic-w4tp3x
– Alexander
Mar 26 at 16:42
|
show 4 more comments
you can use this:
this.local.get('access_token');
or else you can use these methods:
for setting the token:
this.local = new Storage(LocalStorage);
this.local.set("YourTokenValue", this.access_token);
for Getting the token:
toCheckStatus();
function toCheckStatus()
self.local = new Storage(LocalStorage);
self.local.get('access_token').then((token) =>
console.log("token", token);
);
add a comment |
you can use this:
this.local.get('access_token');
or else you can use these methods:
for setting the token:
this.local = new Storage(LocalStorage);
this.local.set("YourTokenValue", this.access_token);
for Getting the token:
toCheckStatus();
function toCheckStatus()
self.local = new Storage(LocalStorage);
self.local.get('access_token').then((token) =>
console.log("token", token);
);
add a comment |
you can use this:
this.local.get('access_token');
or else you can use these methods:
for setting the token:
this.local = new Storage(LocalStorage);
this.local.set("YourTokenValue", this.access_token);
for Getting the token:
toCheckStatus();
function toCheckStatus()
self.local = new Storage(LocalStorage);
self.local.get('access_token').then((token) =>
console.log("token", token);
);
you can use this:
this.local.get('access_token');
or else you can use these methods:
for setting the token:
this.local = new Storage(LocalStorage);
this.local.set("YourTokenValue", this.access_token);
for Getting the token:
toCheckStatus();
function toCheckStatus()
self.local = new Storage(LocalStorage);
self.local.get('access_token').then((token) =>
console.log("token", token);
);
answered Mar 26 at 9:20
Pupinder SinghPupinder Singh
54 bronze badges
54 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353362%2fionic-3-ionic-storage-with-observables%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is your storage API promise based? If it is async -- you can't just pass it to the headers. Use
switchMap
to read value from the storage and switch to the http-get. If it is sync -- then you dont need afromPromise
there.– kos
Mar 26 at 10:02
Ionic storage is promise based ! Can you provide pseudo-code with switchMap? Thnx
– Alexander
Mar 26 at 14:32