我正在尝试将参数传递给服务中定义的函数。参数始终为protected static function getFacadeAccessor()
{
return 'auth.password';
}
。
login.component.ts
undefined
authentication.service.ts
import { Component, OnInit } from '@angular/core';
import { AuthenticationService } from '../authentication.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
providers: [AuthenticationService]
})
export class LoginComponent implements OnInit {
credentials: {
username: '',
password: ''
};
constructor(private _authenticationService: AuthenticationService) {}
ngOnInit() { }
login() {
this._authenticationService.login(this.credentials).subscribe(
response => console.log(response),
error => console.log(error),
() => console.log('Done.')
);
}
我错过了什么?
答案 0 :(得分:2)
您正在完美地传递数据,但问题是您声明了类型为credentials
的变量{ username: '', password: '' };
,您没有为其赋值,这就是undefined
的原因。 :
为变量指定类型,=
指定值。这就是你要找的东西:
credentials: any = {
username: '',
password: ''
};