After configuring my Angular 4 project with a service like this:
const usersURL = 'http://my.super.url.php';
@Injectable()
export class UserService {
users: Observable<User[]>
constructor (public http:Http)
let tick$ = Observable.timer(100, 60000);
this.users = tick$.flatMap(() => http.get(usersURL)).map(res => [res.json()]).publishBehavior(<User[]>[]).refCount();
I came across the PrimeNg library which predominantly uses promises by default as shown here:
@Injectable()
export class CarService {
constructor(private http: Http) {}
getCarsSmall() {
return this.http.get('/showcase/resources/data/cars-small.json')
.toPromise()
.then(res => <Car[]> res.json().data)
.then(data => { return data; });
}
}
I am wondering about the best approach to quickly integrate this library. Should I modify my service to work with promises or should I adjust the code from the PrimeNG documentation? This is my first time working with PrimeNg so any guidance on how to handle this considering that a lot of my existing code relies on Observables would be appreciated. Thank you in advance. You can find more information in the PrimeNg docs here.
Here is an example of my JSON data:
{"status":"OK","data":{"apps":{"weather_icon":"storm","running": {"current":6,"total":12,"sensitive":{"current":1,"total":6},"non_sensitive":{"current":5,"total":6}},"non_running":{"current":6,"sensitive":{"current":5,"unseen":2,"acknowledged":0,"assigned":3},"non_sensitive":{"current":1,"unseen":0,"acknowledged":0,"assigned":1}},"availability": {"current":8,"trend":-6.6},"details":[{"id":1,"label":"Gestion administrative des patients (ORBISAdm)","state":"Critique","state_id":2,"weather_icon":"storm","since":"2h37mn","availability":{"current":68,"trend":"-"},"acknowledged":1,"assigned":1,"assignee":{"id":1,"name":"Thomas Z."}},{"id":2,"label":"Cha\u00eene de messagerie (mail)","state":"Correct","state_id":0,"weather_icon":"sun","since":">6j5h","availability":{"current":100,"trend":"="},"acknowledged":0,"assigned":0},{"id":3,"label":"CRM (CRM)","state":"Correct","state_id":0,"weather_icon":"sun","since":">35j","availability":{"current":100,"trend":"="},"acknowledged":0,"assigned":0}]},