Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Http service not getting called #40

Closed
MadhuSudhanBhaskar opened this issue Dec 2, 2016 · 5 comments
Closed

Http service not getting called #40

MadhuSudhanBhaskar opened this issue Dec 2, 2016 · 5 comments

Comments

@MadhuSudhanBhaskar
Copy link

MadhuSudhanBhaskar commented Dec 2, 2016

Hi,

I have a service in "enableLocationRequest" callback, I see the service function being called but I dont see the service making a http request. This is happening when I make a fresh install of app on emulator.

But if I force kill the app and open it again, I see it to getting all the data. This is happening in Android, have not tested it on IOS.

I have latest build of TNS.

I have some basic code uploaded here
https://github.com/MadhuSudhanBhaskar/NativeNew
Upfront Not a production code

@nsndeck
Copy link
Contributor

nsndeck commented Dec 7, 2016

I've tested your scenario and everything seems OK at least for nativescript-geolocation part. However @angular/http module need some more configuration in order to work. I've just added a call to subscribe method which triggers the http request.

 UserService.prototype.getCityDetails = function () {
        console.log('service call');
        var listCities$;
        this.http
            .get("" + this.baseUrl, { headers: this.getHeaders() })
            .map(mapPersons)
            .catch(handleError)
            .subscribe(function (r) {
            console.log("subscribe called with " + r);
            listCities$ = r;
        });
        console.dump(listCities$);
        return listCities$;
    };

Let me know how this works on your end.

@MadhuSudhanBhaskar
Copy link
Author

Hi @nsndeck
Will try it and keep you posted!

Regards,
Madhu

@MadhuSudhanBhaskar
Copy link
Author

MadhuSudhanBhaskar commented Dec 7, 2016

@nsndeck I see data coming, but I can't return it back to the called function. I am using Typescript.

The outside console.dump(listCities$); before we return is still null.

var listCities$;
       this.http
         .get(`${this.baseUrl}`, {headers: this.getHeaders()})
         .map(mapPersons)
         .catch(handleError)
         .subscribe((r) => {
            listCities$ = r;
           //I get values here
          });
        //Here listCities is null
        console.dump(listCities$);
         return listCities$;

@MadhuSudhanBhaskar
Copy link
Author

MadhuSudhanBhaskar commented Dec 7, 2016

@nsndeck

    getCityDetails()  {
        console.log('service call');
        return Observable.create(observer => {
            var listCities$;
               this.http
                 .get(`${this.baseUrl}`, {headers: this.getHeaders()})
                 .map(mapPersons)
                 .catch(handleError)
                 .subscribe((r) => {
                    listCities$ = r;
                    observer.next(listCities$);
                    observer.complete();
                  });
        });
    }

This is for service

                this.userservice.getCityDetails().subscribe((r) => {

                    console.log('after service call');
                    this.myItems = r;
                    console.dump(this.myItems[0]);
                });
public myItems: RxObservable<Array<ListCities>>;
        <ListView [items]="myItems" class="list-group">
            <template let-item="item" let-i="index" let-odd="odd" let-even="even">
                <GridLayout class="list-group-item" [class.odd]="odd" [class.even]="even">
                    <Label [text]="item.name" ></Label>
                </GridLayout>
            </template>
        </ListView>

I can dump data, but not able to assign data to list view. Can you please help me here :)

@tsonevn tsonevn removed their assignment Dec 8, 2016
@nsndeck
Copy link
Contributor

nsndeck commented Dec 9, 2016

Hi @MadhuSudhanBhaskar,

ListView cannot work with RxObservable's directly. You should use async pipe. Here is an example of using async pipe with nativescript-angular.

@nsndeck nsndeck closed this as completed Dec 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants