I am facing an issue while trying to define a todo object that stores members' usernames and passwords with data fetched using ngmodel. Despite my efforts, I have not been able to successfully initialize this object. I attempted to utilize arrow notation in the logForm function to set this up, but it appears to be ineffective. It seems like the problem lies in the incorrect declaration of the todo object.
import { Component, OnInit } from '@angular/core';
import {BackendDataService} from '../../backend-data.service';
import { map } from 'rxjs/operators';
import { Router } from '@angular/router';
import {LocalStorageService} from '../../local-storage.service';
@Component({
selector: 'app-loginform',
templateUrl: './loginform.component.html',
styleUrls: ['./loginform.component.scss'],
})
export class LoginformComponent implements OnInit {
username: string;
password: string;
todo: Todo;
/*
todo = {
}
*/
constructor(private backendDataService: BackendDataService, private router: Router, private storage: LocalStorageService) {
//constructor = (private backendDataService: BackendDataService, private router: Router, private storage: LocalStorageService) => {
this.todo = new Todo();
}
ngOnInit() {
}
//logForm() {
logForm = () => {
var obv;
//var username;
//var password;
let username = "";
let password = "";
username = this.todo.username; //<<<<ERROR Property 'username' does not exist on type '{}'.
password = this.todo.password;
console.log("username: " + username);
console.log("password: " + password);
this.storage.set("username", username);
this.storage.set("password", password);
obv = this.backendDataService.postLogin(username, password);
obv.pipe(map( res => res)).subscribe(data => {
console.log( data.response);
console.log("isAuthenticated: " + data.isAuthenticated);
if (data.isAuthenticated == true)
{
console.log("response was successful");
this.router.navigateByUrl('/home');
//this.router.navigate(['/home']);
}
//console.log(data);
//console.log(data.balance);
//this.balance = data.balance;
//this.name = "elephant";
//this.bitcoinAddress = data.bitcoinAddress;
});
}
}
class Todo
{
username: string;
password: string;
test() {
console.log("TEST RAN<<<<");
}
}