angular - 角度如果传递2个数据的问题
问题描述
我使用硬编码登录。我有 3 种类型的用户。
if(this.loginForm.value.email == 'admin' && this.loginForm.value.password == 'admin'){
console.log(`found corresponding user.`);
this.router.navigate(['/dashboard/home']);
}
if(this.loginForm.value.email == 'USapparel&textile' && this.loginForm.value.password == 'admin'){
console.log(`found corresponding user.`);
this.router.navigate(['/dashboard/home', {company_id: '39'}]);
}
if(this.loginForm.value.email == 'USapparel&textile0118/003' && this.loginForm.value.password == 'admin'){
console.log(`found corresponding user.`);
this.router.navigate(['/dashboard/home', {company_id: '39', policy_id: 'IGT/D/PHI3/0000000001/0118/003'}]);
}
我在一个中传递数据,我没有传递任何东西,在第二个 company_id 和第三个 company_id 和 policy_id 中。
在家庭组件中
if(this.company_id){
this.getSamad(this.company_id);
this.company = false;
}
if(this.policy_id){
this.getSamad2(this.policy_id);
this.company = false;
}
我有 2 个函数 getSamad 和 getSamad2 。但是当我只有 company_id 时,它也使用 getSamad2 函数。意思是我只传递 company_id 所以它会使用 getSamad 函数?但它使用 getSamad2 函数。任何人都可以帮助做到这一点吗?
解决方案
尝试:
if(this.policy_id) {
// policy_id available
}
else {
// policy_id not available
}
如果您想将其作为参数发送,那么对于第一个导航方法
this.router.navigate(['/dashboard/home', {company_id: '39', policy_id : null }]);
推荐阅读
- batch-file - Can't stop VBScript in batch file
- sql - 在sql中使用count和join
- android - URL 编码因特殊字符而失败。#安卓
- c# - C# Determine if a char at index is between two characters in a string
- java - How do you make a button in android that opens a new activity and this activity is not just a default activity its a custom one
- javascript - 参数必须是函数
- c# - 如何确定 JObject 的 JProperty 是否为数组?
- xcode - Verifying "Xcode" on every macOS boot
- autodesk-forge - How to solve flickering issue of custom mesh
- r - Is there an R function to convert columns to given types?