last day (15 days later) » 

8:41 PM
1
A: Add Header to the API Http request, Angular 2, Ionic 2

Daniel PlisckiHeaders must be set inside the RequestOptions, which is the second parameter http.get() Besides you have a syntax error in your code. Request options is the second parameter of .get(url, {}), and you wrote like this: .get(url),{} this.http.get("https://twit.tv/api/v1.0/people/77",{"Headers"...

 
So to add three headers, i do myHeaders.set('Content-type', 'application/json') line three times?
im getting this... SyntaxError: /Users/Carl/TwitCasts/app/pages/latest-page/latest-page.js: Unexpected token (18:10) while parsing file: /Users/Carl/TwitCasts/app/pages/latest-page/latest-page.js
 
To add multiple headers use headers.append()
 
myHeaders.append ?? or just headers.append
 
Is this the original error? As I mentioned you had a syntax error in your snippet. Did you corrected that?
 
That's what have... pastebin.com/JexncDzL
 
8:41 PM
myHeaders.append(). myHeaders its just the name declared, you name it like you want
Ohh wait here. You just copy-pasted all my snippet into your code. You have to adjust variables names
 
Im looking at it it all looks like all the vars match ? what do i need to change
 
Line 28. _http.get where you declared as http
 
do i need to put the url in there? or.. this.http.get(url, opt);
 
get rid of this line and change line 30 to: this.http.get("twit.tv/api/v1.0/people/77",opt).subscribe.subscribe) (data => { the rest remain the same
hi, I have edit my post and included the complete code of construct() method
check it again
 
Hey :) thanks for helping. i'm not new to coding but i am new to angular 2 take a bit to get my head round it
when im running "ionic serve --lad" in terminal
im still getting... SyntaxError: /Users/Carl/TwitCasts/app/pages/latest-page/latest-page.js: Unexpected token (18:10) while parsing file: /Users/Carl/TwitCasts/app/pages/latest-page/latest-page.js
Do i need any extra imports? or anything
 
8:54 PM
From the code you have shared I don't see any more syntax errors. It can be something else
 
9:29 PM
acording to a syntax checker there shouldnt be a : in these
let opt: RequestOptions
let myHeaders: Headers = new Headers
cant see how that would be the case but thats what it says
 

last day (15 days later) »