Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Bind data comming from http post #29

Closed
glenngsanchez opened this issue Apr 16, 2018 · 6 comments
Closed

Unable to Bind data comming from http post #29

glenngsanchez opened this issue Apr 16, 2018 · 6 comments
Labels
question Further information is requested

Comments

@glenngsanchez
Copy link

Hi, how do I bind data coming from http post?

this.carmodels = [];
 this.getCarModels();

 this.carmodels.push({id:12,name:"Carmodel1"});
 this.carmodels.push({id:13,name:"Carmodel2"});

when logged the data in console, more data. but select-searchable only shows the last 2 (Carmodel1, Carmodel2).

I tried moving the last 2 lines inside http success, and it does not show any data anymore.

Thanks

@eakoriakin
Copy link
Owner

eakoriakin commented Apr 16, 2018

Hey, this.getCarModels() is an asynchronous operation. You need to do the assignment inside callback.

this.getCarModels().subscribe(carmodels => {
    this.carmodels = carmodels;

    // And then add some static items to the and of the array.
    this.carmodels.push({id:12,name:"Carmodel1"});
    this.carmodels.push({id:13,name:"Carmodel2"});
});

@glenngsanchez
Copy link
Author

Hi eakoriakin,

I updated my code and follow your sample source file. I created an observable method like below:

function getCarModelsAsync(timeout=0):Observable<CarModelObj[]>{

    return new Observable<CarModelObj[]>(observer => {
      observer.next(this.getCarModels());
      observer.complete()
    }).pipe(delay(timeout));
 }

this.getCarModels() is getting data form http post.

and this sis how I called it:

this.getCarModelsAsync().subscribe(data =>{
      this.carmodels = data;
      console.log(this.carmodels);
    });

I notice some delay of fetching the data, and the list is still not showing.

Can you enlighten me more on this?

Thanks for the help.

@eakoriakin
Copy link
Owner

It works for me, can you show me your html for <select-searchable>?

@glenngsanchez
Copy link
Author

This is my select-searchable

<select-searchable
[isEnabled]="!isReadOnly"
title="Model"
[(ngModel)]="carmodel"
[items]="carmodels"
itemValueField="Id"
itemTextField="ModelName"
[canSearch]="true"
(onChange)="modelChanged($event)">

@eakoriakin
Copy link
Owner

Hi @glenngsanchez, did you manage to solve the issue?

@eakoriakin eakoriakin added the question Further information is requested label May 4, 2018
@eakoriakin
Copy link
Owner

Closed for inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants