Reputation: 15578
I am new angular2 so please ignore if you find it the basic question.
I have a variable of type Observable
users: Observable<User[]>;
and in the constructor, I am filling it
constructor(private roleService: RoleService, private userService: UserService) {
this.users = this.userService.getAllUsers();
}
Now I want to manipulate/iterate the data of this.users
. How can I do that?
Upvotes: 0
Views: 620
Reputation: 657108
You can use map
or any other of the long list of available operators.
You need to subscribe to execute the observable, otherwise it won't do anything. You can also use .forEach(...)
, .toArray()
, (and others) instead of subscribe()
:
constructor(private roleService: RoleService, private userService: UserService) {
this.users = this.userService.getAllUsers()
.map(val => val + 'xxx')
.subscribe(val => console.log(val));
}
See also https://blog.thoughtram.io/angular/2016/01/06/taking-advantage-of-observables-in-angular2.html
Upvotes: 1