我有一个signUp表单,我从前端提供电子邮件和密码,并从打字稿中提供活动的,role_id字段。我在安慰输出中活跃但不是role_id。我想如果我可以在ts文件的安慰输出中获得role_id,那么我的错误可能会解决。我在apiservice部分获得了所有必填字段,但没有在我的组件文件中获取..任何人都可以帮我解决这个问题。
答案 0 :(得分:1)
您需要使用loggedIn variable
并将其用于toggle
警告弹出窗口,
Conponent Variable:
public loggedIn = false;
登录方式:
login(email, password) {
this.localSt.store('boundValue', email);
var data = {
email: email,
password: password
};
this.ApiService
.login(data)
.subscribe(
user => {
this.signIn.hide();
this.loggedIn = true;
this.toasterService.pop('success', 'SignIn Successfull');
this.myFav = true;
}, error => {
this.myFav = false;
if (error.data && error.data.length > 0) {
this.toasterService.pop('error', error.data);
} else {
this.toasterService.pop('error', 'Something went wrong!');
}
})
}
弹出式方法:
openPopup(event) {
if (!this.loggedIn) {
event.preventDefault();
this.signIn.show();
}
}
}
答案 1 :(得分:0)
由于public
是类中使用的关键字,因此您的代码不正确。
变化:
public user:NewUsers = new NewUsers();
public _id:any=2;
newUser(user) {
var data = {
email:user.email,
password:user.password,
active:user.active,
role_id:this._id
}
//....
为:
let user:NewUsers = new NewUsers();
let _id:any=2;
newUser(user) {
var data = {
email:user.email,
password:user.password,
active:user.active,
role_id:_id
}
//....
它应该有效。您还可以围绕剩余的ts
代码打包课程,之后您可以在该课程中设置这些字段public
。