Guest User

Untitled

a guest
Apr 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. getCatalogs(): Observable<Catalog[]> {
  2. const api_path = this.dataUrl + `metadata/getcatalogs/name/?user=${this.user.username}&password=${this.user.password}`;
  3. return this.http.get<Catalog[]>(api_path);
  4. }
  5.  
  6. onSelect(user: User): void {
  7. this.selectedUser = user;
  8. this.datasourceService.user = user; // sets the user, as i can't figure out how to send it as a parameter, and subscribe to that call
  9. this.datasourceService.getCatalogs() // had to run this here so that the Observable would have at least one subscription to make it run.
  10. .subscribe(catalogs => {this.catalogs = catalogs; });
  11. }
  12.  
  13. @Input() user: User;
  14. public catalogs$: Observable<Catalog[]>;
  15. constructor(private datasourceService: DatasourceService) { }
  16.  
  17. ngOnInit() {
  18. this.catalogs$ = this.datasourceService.getCatalogs();
  19. this.datasourceService.getCatalogs()
  20. .subscribe(catalogs => {this.catalogs = catalogs; });
  21. }
  22.  
  23. <div *ngIf="user">
  24.  
  25. <h3>Catalogs for User: {{user.username}}</h3>
  26.  
  27.  
  28. <ul >
  29. <li *ngFor="let catalog of catalogs$ | async">
  30. {{ catalog.name }}
  31. </li>
  32. </ul>
  33.  
  34. </div>
  35.  
  36. providers: [DatasourceService],
Add Comment
Please, Sign In to add comment