In the code snippet below, an observable has been created:
private permissionSubject = new Subject<any>();
permissionObservable$ = this.permissionSubject.asObservable();
constructor( public apiService: ApiService) { }
updatePermissionsData(permissionData){
this.permissionSubject.next(permissionData);
}
getPermissions(){
return this.apiService.get('/getUserPrivileges')
.map(data => data)
}
The purpose here is to push incoming data to the Observable every time it is received.
For instance: Let's say we have an observable -> [1, 2] and we receive a new data which is 3, the updated observable will become [1, 2, 3]
What I want to achieve is to remove the values 1 and 2 from the Observable before adding the new value 3. How can this be done?
Will Observable.empty() accomplish this, and if so, how should I modify my code?
Despite searching on stackoverflow, I couldn't find a solution to my problem, so I'm seeking help here...
Updated code
Subscribing observable
checkPermissions() {
this.checkPermService.permissionObservable$.subscribe(
// The following block gets executed multiple times whenever new data is received via the observable
data => {
this.saveMenuItemsOnPermissions(data)
}
)
}