Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ngIf上的更改检测导致异常_Angular_Meteor_Ionic Framework_Angular Meteor - Fatal编程技术网

Angular ngIf上的更改检测导致异常

Angular ngIf上的更改检测导致异常,angular,meteor,ionic-framework,angular-meteor,Angular,Meteor,Ionic Framework,Angular Meteor,我在变更检测方面遇到了一个问题,我不确定该怎么解决 CEChats.find({ group: {$in: groupIds}, }) .map((sub2: any) => { sub2.forEach((chat)=> { this.findLastChatMessage(chat._id, chat.lastMessage).subscribe(lmsgsub=> { chat

我在变更检测方面遇到了一个问题,我不确定该怎么解决

    CEChats.find({
        group: {$in: groupIds},
    })
    .map((sub2: any) => {
      sub2.forEach((chat)=> {
          this.findLastChatMessage(chat._id, chat.lastMessage).subscribe(lmsgsub=> {
            chat.lastMessage = lmsgsub;
            chat.unseen = !chat.lastMessage.seenBy.some((x)=>x==this.user._id);
            this.appRef.tick();
          });
      });
      this.groupChats = sub2;
      this.appRef.tick();
    });
我在共享服务组件中执行此调用。 (无@组件或@页面)

groupChats用于另一个组件(聊天列表),该组件使用
*ngIf
上的不可见键来显示/隐藏图标

<ion-icon name="radio-button-on" *ngIf="chat.unseen"></ion-icon>

当我切换到聊天列表的子页面(聊天)时,我得到
“ExpressionChangedTerithasBeenCheckedError:表达式在检查后已更改。上一个值:“true”。当前值:“false”。

将changeDetection更改为onPush没有任何帮助,我无法在服务中使用
changeDetectorRef
,因为它没有可用的提供程序(因为它不是一个组件?)

我还尝试了使用
ApplicationRef.tick()
,但同样没有帮助。 我在内部订阅(
lastMessage
)和
groupChats
的设置中使用了appilcationRef。两者都没有帮助

导致值更改的更新在提取消息集合时在子聊天页面中完成

应用程序使用用户ID(作为已读回执)更新以前未看到的每条消息,这反过来会导致上面的订阅更新(
findLastMessage()


为此,我正在使用Ionic with angular meteor。

ApplicationRef.tick()会触发更改检测,因此如果我将changeDetectionStrategy.on添加到聊天列表页面,它可能会工作。还没试过,我五岁的时候会更新的,好像没用。我已经重构了我的代码,以更好地使用一个可观察的订阅,它似乎正在工作。我将在morningApplicationRef.tick()中作为答案发布我所做的事情。tick()会触发更改检测,因此,如果我将changeDetectionStrategy.onPush添加到聊天列表页面,它可能会工作。还没试过,我五岁的时候会更新的,好像没用。我已经重构了我的代码,以更好地使用一个可观察的订阅,它似乎正在工作。我会在早上把我所做的作为回答