检查订阅角度10中是否存在数组值
Check the array value exist in subscribe angular10
我有一些 const 数组值,我在订阅中有响应值,我想检查 const 数组值是否可用 response.i不知道如何在订阅中使用映射和过滤器。如果该值可用,那么 checkval 应该 return true 否则 false.i 可以使用某些函数来完成,但在这里我需要使用 rxjs operators
Response:
{
"testLoad": 1603367083993,
"checkData": "test1"
"type": "flag",
"title": "TestFlag",
"styleId": "test",
"BodyContent": {
"properties": "undefined"
}
}
const styleid: Array<string> = ['test1','test2','test3'];
public checkVal(){
this.idVal =this.data.getresponse().subscribe((response => console.log(response ));
}
因为我是 angular rxjs 的新手,你能指导我并帮助解决这个问题吗
根据我的理解,如果 response.checkData
值包含在 pageUid
数组中,您想要 return 一个 true
可观察对象。
您可以执行以下操作:
this.data.getresponse().pipe(
map(response => pageUid.includes(response.checkData)),
).subscribe(checkResult => console.log(checkResult));
我有一些 const 数组值,我在订阅中有响应值,我想检查 const 数组值是否可用 response.i不知道如何在订阅中使用映射和过滤器。如果该值可用,那么 checkval 应该 return true 否则 false.i 可以使用某些函数来完成,但在这里我需要使用 rxjs operators
Response:
{
"testLoad": 1603367083993,
"checkData": "test1"
"type": "flag",
"title": "TestFlag",
"styleId": "test",
"BodyContent": {
"properties": "undefined"
}
}
const styleid: Array<string> = ['test1','test2','test3'];
public checkVal(){
this.idVal =this.data.getresponse().subscribe((response => console.log(response ));
}
因为我是 angular rxjs 的新手,你能指导我并帮助解决这个问题吗
根据我的理解,如果 response.checkData
值包含在 pageUid
数组中,您想要 return 一个 true
可观察对象。
您可以执行以下操作:
this.data.getresponse().pipe(
map(response => pageUid.includes(response.checkData)),
).subscribe(checkResult => console.log(checkResult));