Answer the question
In order to leave comments, you need to log in
I rewrite the Http module on HttpClient, how to fix the errors that have arisen?
ERRORS:
ERROR in src/app/common/auth.service.ts(44,30): error TS2339: Property 'success' does not exist on type 'Object'.
src/app/common/auth.service.ts(45,56): error TS2339: Property 'message' does not exist on type 'Object'.
src/app/common/auth.service.ts(47,45): error TS2339: Property 'message' does not exist on type 'Object'.
src/app/common/auth.service.ts(48,46): error TS2339: Property 'token' does not exist on type 'Object'.
src/app/login/login.component.ts(33,30): error TS2339: Property 'success' does not exist on type 'Object | any[]'.
Property 'success' does not exist on type 'Object'.
src/app/login/login.component.ts(34,50): error TS2339: Property ' message' does not exist on type 'Object | any[]'.
Property 'message' does not exist on type 'Object'.
auth.service :
login(oUser) {
return this.http.post('http://localhost:1978/api/login', JSON.stringify(oUser), httpOptions).pipe(
tap(user => {
if (user.success) {
this.currentUser = <IUser>user.message;
let userObj: any = {};
userObj.user = user.message;
userObj.token = user.token;
localStorage.setItem('currentUser', JSON.stringify(userObj));
}
}),
catchError(this.handleError('login', []))
);
}
loginUser(): void {
if (this.loginForm.dirty && this.loginForm.valid) {
this.authService.login(this.loginForm.value)
.subscribe(data => {
if (data.success === false) {
this.messages.error(data.message);
} else {
this.messages.success('Login successful.');
this.router.navigate(['report']);
}
this.loginForm.reset();
});
}
}
oUser.save(function(err) {
if(err){ res.status(400).json({ success: false, message:`Error processing request ${err}`}); }
res.status(201).json({
success: true,
message: 'User created successfully, please login to access your account.'
});
});
Answer the question
In order to leave comments, you need to log in
Where are all types? .ts files and no type specification. It says that user is of type Object . And on Object there are no "success", "message" fields, etc. You must explicitly specify the type of the object.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question