These are chat archives for angular/angular-2-ionic-2

11th
Mar 2018
DeveloperMatheus
@DeveloperMatheus
Mar 11 06:50
Hello everyone, i'm learning http requests and i would like some help with a nested JSON with the swapi: https://swapi.co/ can someone help me? Thanks in advance!
UncertaintyP
@UncertaintyP
Mar 11 06:59
Just ask
DeveloperMatheus
@DeveloperMatheus
Mar 11 06:59
Thanks mate!
So, i have this free api right? And i can get the data from the 'first level' object
I can get the atributes like: title, episode_id, opening_crawl, producer, etc
That works like a charm, but now i'm struggling to get the nested part of the JSON like, the planets inside a film
when i make something like {{ film. planets }} it shows the URL in my ionic page, and i can't get the name or other json atributes from the planets itself
I can show my project code if you want
UncertaintyP
@UncertaintyP
Mar 11 07:12
So you need to make a new request to fetch them as well
DeveloperMatheus
@DeveloperMatheus
Mar 11 07:12
hmmm
I did that, but the biggest thing that i could achieve was... to show all the planets on all the films lmao
on the films details, sorry
Let me express more clearly, i have 2 pages, one for the list of the films (they are also buttons)
and if i click on one film, i go the a "details page" of this film
and in this filmDetailsPage, i could only get all the planets, but not the specific data for the specific film lmao
UncertaintyP
@UncertaintyP
Mar 11 07:16
So on the first page you already have the data of the film and your problem is to now show it on the specific film page?
DeveloperMatheus
@DeveloperMatheus
Mar 11 07:17
Not exactly
oh i mean, yes, you're right
i'm having problems to show some data on the specific film page, yes

On the first page i have:

A list of films

On the second page:

A film specific page -> I can get some data about the film itself, but not other JSON like the planets, characters... Those type of JSON are below the film object

let me show to you
{
"count": 7,
"next": null,
"previous": null,
"results": [
{
"title": "A New Hope",
"episode_id": 4,
"opening_crawl": "It is a period of civil war.\r\nRebel spaceships, striking\r\nfrom a hidden base, have won\r\ntheir first victory against\r\nthe evil Galactic Empire.\r\n\r\nDuring the battle, Rebel\r\nspies managed to steal secret\r\nplans to the Empire's\r\nultimate weapon, the DEATH\r\nSTAR, an armored space\r\nstation with enough power\r\nto destroy an entire planet.\r\n\r\nPursued by the Empire's\r\nsinister agents, Princess\r\nLeia races home aboard her\r\nstarship, custodian of the\r\nstolen plans that can save her\r\npeople and restore\r\nfreedom to the galaxy....",
"director": "George Lucas",
"producer": "Gary Kurtz, Rick McCallum",
"release_date": "1977-05-25",
"planets": [
"https://swapi.co/api/planets/2/",
"https://swapi.co/api/planets/3/",
"https://swapi.co/api/planets/1/"
],
UncertaintyP
@UncertaintyP
Mar 11 07:20
I remember some had a Star Wars hackaton app, lemme search
DeveloperMatheus
@DeveloperMatheus
Mar 11 07:20
thank you!
UncertaintyP
@UncertaintyP
Mar 11 07:22
Here is his blog post https://blog.ionicframework.com/yann-braga-my-ionic-success-story/ and the source code (the film-details page) You can see how characters of the film are loaded https://github.com/yannbf/may-the-4th/blob/master/src/pages/film-detail/film-detail.ts
DeveloperMatheus
@DeveloperMatheus
Mar 11 07:22
Omg let me see this lmao
And this guy is also brazilian i'm so proud now
UncertaintyP
@UncertaintyP
Mar 11 07:23
:D
DeveloperMatheus
@DeveloperMatheus
Mar 11 07:24
loadCharacters() {
if(this.film){
for(let i in this.film.characters) {
let character = this.film.characters[i].split('/')[5];
this.swapi.getPerson(character).subscribe(characterData => {
characterData.photo = this.getAvatar(characterData);
this.characters.push(characterData);
});
}
}
}
i will try the characters first, and then i will try the planets later
But mate, thank you sooo much!
UncertaintyP
@UncertaintyP
Mar 11 07:25
No problem! :thumbsup:
Owen Melbourne
@OwenMelbz
Mar 11 09:01
I always swap the overly complicated angular http client for a axios 🙄
UncertaintyP
@UncertaintyP
Mar 11 09:27
this.http.get('url') is complicated? :D
Owen Melbourne
@OwenMelbz
Mar 11 09:29
All the extra subscribe shit, then things like setting custom headers in interceptors - just gimme a simple promise kthnx
UncertaintyP
@UncertaintyP
Mar 11 09:32
I was like that before really getting my head around reactive programming and don't wanna miss it now
UncertaintyP
@UncertaintyP
Mar 11 09:40
image.png
:laughing:
milottit
@milottit
Mar 11 18:25
hello
somesbody's here?
bwhiting2356
@bwhiting2356
Mar 11 18:26
what's up?
milottit
@milottit
Mar 11 18:30
I have an annoying trouble
When I run '''ionic cordova run android --livereload'''
my system freezes for ever and I have to reboot brutally
bwhiting2356
@bwhiting2356
Mar 11 19:00
sorry i don't know android
milottit
@milottit
Mar 11 19:14
that's a pity :(