Skip to content

Instantly share code, notes, and snippets.

@AhsanAyaz
Created April 9, 2018 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhsanAyaz/8056413be979534d77456d360b9529e7 to your computer and use it in GitHub Desktop.
Save AhsanAyaz/8056413be979534d77456d360b9529e7 to your computer and use it in GitHub Desktop.
AppComponent after adding QueryList code for getting list items
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