When working with my component, I am retrieving data from a JSON file through services and subscribing to it. There is a condition check in place to stop the subscription once a specific criteria is met, but unfortunately, it doesn't seem to be working as expected.
Service
getUserData() {
const url = './assets/json/userslist.json';
return this.http.get(url);
}
Component
const subscription = this.getuser.getUserData().subscribe(data => {
Object.values(data).forEach((userdetail) => {
// tslint:disable-next-line:max-line-length
if (userdetail.username.indexOf(form.value.email) !== -1 && userdetail.password == form.value.password) {
console.log('asd');
if (userdetail.active == true) {
console.log('asasdfasd');
this.EventEmitterObj.emit(form.value.email);
this.router.navigateByUrl('/home');
} else if (userdetail.active == false) {
console.log('asd23423432');
this.deactivateAlert = 'The account is deactivated';
}
subscription.unsubscribe();
console.log('issue');
} else {
console.log('12341243');
this.deactivateAlert = 'Incorrect Username/Password';
}
});
});