我需要在没有ngFor的情况下使用异步管道.我需要检查与observable异步加载的对象的属性.
这就是我想要的,但不起作用:
<ion-item *ngIf="user$.anonymouse | async">
<ion-label>Login</ion-label>
</ion-item>
Run Code Online (Sandbox Code Playgroud)
//编辑:当我使用上面的代码时出现此错误
EXCEPTION:[!user $ .anonymouse |中的管道'AsyncPipe'的参数'true'无效 在SettingsPage @ 27:22中的异步]
有什么方法可以解决这个问题吗?
我知道我可以在Ctrl中将这个observable订阅商店值变成普通变量但是我不想这样做,因为性能等等.
我有对象流,我需要比较当前对象是否与以前相同,在这种情况下发出新值.我发现distinctUntilChanged操作符应该完全符合我的要求,但由于某种原因,除了第一个之外它永远不会发出值.如果我删除distinctUntilChanged值正常发出.
我的代码:
export class SettingsPage {
static get parameters() {
return [[NavController], [UserProvider]];
}
constructor(nav, user) {
this.nav = nav;
this._user = user;
this.typeChangeStream = new Subject();
this.notifications = {};
}
ngOnInit() {
this.typeChangeStream
.map(x => {console.log('value on way to distinct', x); return x;})
.distinctUntilChanged(x => JSON.stringify(x))
.subscribe(settings => {
console.log('typeChangeStream', settings);
this._user.setNotificationSettings(settings);
});
}
toggleType() {
this.typeChangeStream.next({
"sound": true,
"vibrate": false,
"badge": false,
"types": {
"newDeals": true,
"nearDeals": true,
"tematicDeals": false,
"infoWarnings": false,
"expireDeals": true
}
});
}
emitDifferent() …Run Code Online (Sandbox Code Playgroud)