Looking to retrieve a string value from an HTML input inside an array in Angular 5 using a service file within a component.
My code
login.component.ts
export class LoginComponent implements OnInit {
userData = [];
constructor(private router: Router, private usersList: OperationService) {
}
ngOnInit() {
this.usersList.usersData.subscribe(getData => {
this.userData = getData;
});
}
login(login: NgForm) {
if (login.value.userfield === this.userData) {
this.router.navigate(['home']);
}
}
}
operation.service.ts
export class OperationService {
constructor() {}
private users = new BehaviorSubject<any>([
{
name: 'admin',
password: 'lol'
}
]);
usersData = this.users.asObservable();
}
Various attempts have been made such as:
this.userData.find(x => x.username == login.value.userfield )
or
this.userData.indexOf(login.value.userfield)
or
login.value.userfield === this.userData
or
JSON.stringify(this.userData)
However, none of these methods seem to be working. Is there an alternative approach that should be considered? Am I overlooking something?