Answer the question
In order to leave comments, you need to log in
Isn't it redundant to use rxjs/Observable?
Please tell me what is the point of using the rxjs library in angular, in particular rxjs / Observable?
In my opinion, you can do without it.
service:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class UsersService {
constructor(private http: Http) { };
getUsers(): Promise<Object> {
let users = this.http.get('../assets/json/users.json');
console.log(users);
return users.toPromise();
};
}
private getAllUsersData(): void {
this.usersService.getUsers().then(
data => {
console.log(data);
this.allUsersData = JSON.parse(data._body);
console.log(this.allUsersData);
},
err => {
console.log('err')
})
};
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Config } from '../config';
@Injectable()
export class VoteService {
constructor(private http: Http) { };
getVotes(): Observable<any> {
return this.http.get(Config.host + 'assets/json/feedback_0.json');
};
}
Answer the question
In order to leave comments, you need to log in
In Angular, almost all (if not all) asynchronous operations return an Observable. By avoiding its use, you will not get any gains, but on the contrary, make your life much more difficult by breaking out of the framework ecosystem. Here is an article that helped me deal with rxjs https://habrahabr.ru/company/infopulse/blog/338910/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question