-
Notifications
You must be signed in to change notification settings - Fork 8
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
How to use API data #16
Comments
If you can post an example of how you're trying to pull in data, I might be able to give an idea of how to incorporate it. |
Thanks so much for getting back with me, I am pasting my service.ts and my component.ts to give you an idea on what I am doing. I slightly modified your custom-listbox.component but I am not sure what I need to do in the app.component to make this work. Or do I need to modify the app.component instead to pull in the data. Please let me know. my service file:import { Injectable } from '@angular/core'; @Injectable() // private servUrl = "http://www.mocky.io/v2/5eb451840e0000f359081b47"; constructor(private http: HttpClient) { // fetchItems() { public fetchItems(){
} my custom-listbox.component slightly modified:import { Component, EventEmitter, IterableDiffers, Input, Output, OnInit } from '@angular/core'; @component({
} |
You could do this without creating your own CustomListboxComponent. To use the standard , you could do something like in the service: fetchItems(){
return this.http.get('http://www.mocky.io/v2/5eb451840e0000f359081b47');
} And then the component's template: <dual-list [source]="items" key="name" display="name" [(destination)]="confirmed">
</dual-list> And in the source file component that uses the dual-list: export class MyComponent implements OnInit {
items = [];
constructor(private listboxService: ListboxService) {}
ngOnInit() {
this.listboxService.fetchItems().subscribe( data => this.items = data.items );
}
} To make your own CustomListboxComponent, you'll need to populate the array somehow, so in your code for it, something like: ngOnInit () {
// this.source = this.listboxService.fetchItems();
this.listboxService.fetchItems().subscribe( data => this.source = data.items );
this.available = new BasicList(DualListComponent.AVAILABLE_LIST_NAME);
this.updatedSource();
this.updatedDestination();
} Or something like that. I've not tested the code to make sure it compiles, but this hopefully will give you an idea. You need to assign/update the dual list's source array of items for the available side. With a custom dual-list, you can see all the guts you're overriding and/or basing it upon here: dual-list.component.ts. (Note if you are also going to pull the confirmed from an api, you'll need to make sure the source array is inclusive of the confirmed array too.) |
Thank you so much it worked like magic!! |
Hello I wanted to ask how is it possible to add the filter to my custom-list box. Do I just add it as it is or I should make couple changes? |
Hi David,
I wanna use your custom-dual-listbox for a project, I am kind of new to Angular. How can I pull data into the picklist using an API. You have it hard coded in app.component. I have written a service with an API but not sure how to implement it. Any help would be highly appreciated.
Thanks
Ray
The text was updated successfully, but these errors were encountered: