I am encountering multiple errors in my code. I am using Angular 2 with TSLint:
constructor(http: Http) {
this.http = http;
--> let currentUser = JSON.parse(localStorage.getItem("currentUser"));
this.token = currentUser && currentUser.token;
}
I am getting the following error in currentUser:
message: 'expected variable-declaration: 'currentUser' to have a typedef
;
public loginC (username: string, password: string): Observable<boolean> {
return this.http.post( authURL + loginURL,
--> JSON.stringify({ password: password, username: username }))
.map((response: Response) => {
let token: string = response.json() && response.json().token;
if (token) {
this.token = token;
--> localStorage.setItem("currentUser", JSON.stringify({token: token, username: username}));
return true;
} else {
return false;
}
});
}
Additionally, in
password: password, username: username
I am encountering: message: 'Expected property shorthand in object literal.
I have a better understanding now. And finally, I can define a simple model: any {}
;
export class LoginComponent {
--> public model: any = {};
public loading: boolean = false;
public error: string = "";
constructor (private router: Router, private authenticationService: ServerDataComponent) {
//
}
public login(): void {
this.loading = true;
this.authenticationService.loginC(this.model.username, this.model.password)
.subscribe(result => {
--> if (result === true) {
this.router.navigate(["/table_per"]);
} else {
this.error = "Incorrect login and/or password entered";
this.loading = false;
}
});
}
Using 'any' is not allowed -
Type declaration of 'any' is forbidden
;
For the result -
expected arrow-parameter: 'result' to have a typedef