Angular 将数据数组传递给函数5
我是新来的。 我有一个这样的函数Angular 将数据数组传递给函数5,angular,typescript,angular5,Angular,Typescript,Angular5,我是新来的。 我有一个这样的函数 this.login(credentials); 我需要在此数组中传递从该数组中的webservice获取的用户名和密码。在php中,我这样做: $credentials = array(['username'=> $response.user.username, 'password'=> $response.user.password]); 如何在Angular5中获得相同的结果?也许您可以使用对象 var credentials= {use
this.login(credentials);
我需要在此数组中传递从该数组中的webservice获取的用户名和密码。在php中,我这样做:
$credentials = array(['username'=> $response.user.username, 'password'=> $response.user.password]);
如何在Angular5中获得相同的结果?也许您可以使用对象
var credentials= {username:"Blabla", password:"Blabla"};
JavaScript/TypeScript中不能有字符串索引,但可以使用对象存储凭证数据
this.credentials = {
username: response.user.username,
password: response.user.password
}
假设响应有一个属性user,该属性具有用户名和密码
然后可以像这样访问这些值
this.credentials.username
this.credentials.password
您可以尝试以下方法:
interface User{
username : string ;
password : string ;
}
private credentials : User[] = [] ;
为您服务:
credentials.push({username : response.user.username , password:response.user.password})
您想以角码形式传入函数或从函数中获取数据?令人印象深刻。请告诉我,您是如何在PHP中启用点符号$response.user.username的?它是特定于版本的吗?