Created
April 9, 2018 10:55
-
-
Save AhsanAyaz/8056413be979534d77456d360b9529e7 to your computer and use it in GitHub Desktop.
AppComponent after adding QueryList code for getting list items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, QueryList, ViewChildren } from "@angular/core"; | |
import { UsersService } from "./core/services/users.service"; | |
import { first } from "rxjs/operators"; | |
import { ListKeyManager } from "@angular/cdk/a11y"; | |
import { ListItemComponent } from "./core/components/list-item/list-item.component"; // importing so we can use with `@ViewChildren and QueryList | |
@Component({ | |
selector: "app-root", | |
templateUrl: "./app.component.html", | |
styleUrls: ["./app.component.scss"] | |
}) | |
export class AppComponent implements OnInit { | |
users: any; | |
isLoadingUsers: boolean; | |
keyboardEventsManager: ListKeyManager<any>; | |
@ViewChildren(ListItemComponent) listItems: QueryList<ListItemComponent>; // accessing the ListItemComponent(s) here | |
constructor(private usersService: UsersService) {} | |
ngOnInit() { | |
this.isLoadingUsers = true; | |
this.usersService | |
.getUsers() | |
.pipe(first()) | |
.subscribe(users => { | |
this.users = users; | |
this.isLoadingUsers = false; | |
this.keyboardEventsManager = new ListKeyManager<any>(this.listItems); // initializing the event manager here | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment