showDateCriteria = combineLatest(this.myForm.controls['name'].valueChanges, this.myForm.controls['age'].valueChanges, (name, age) => ({name, age}))
.subscribe(val => !(val.name==null ||val.age==null ));
我用combineLatest运算符和showDateCriteria尝试了这段代码
<div *ngIf="{{showDateCriteria | async}}">Show This</div>
即使满足特殊条件,我也无法展示qazxsw poi
<div>
正如错误所说https://stackblitz.com/edit/angular-rs3d7a。
你试图异步管道订阅,这是没有意义的。
你应该管道流。
ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
编辑:
你也应该this.showDateCriteria =
combineLatest(
this.myForm.controls['name'].valueChanges,
this.myForm.controls['age'].valueChanges, (name, age) => ({
name,
age
}));
this.showDateCriteria.subscribe(val => !(val.name == null || val.age == null));
,否则startWith
将不会触发。此外,逻辑是错误的,当它们中的任何一个不为空时,你应该返回combineLatest
boolean
,如下所示:
true
this.showDateCriteria = combineLatest(
this.myForm.controls['name'].valueChanges.pipe(startWith(null)),
this.myForm.controls['age'].valueChanges.pipe(startWith(null)),
(name, age) => {
console.log(name);
return name || age;
});