未从服务Angular 8中获取更新的值[关闭]

问题描述 投票:0回答:1

我有一项共同的服务,我正在使用我的服务通过组件之间的click函数更改变量值。但是我得到了一个越​​来越不确定的错误,也

ERROR
Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngSwitch: count1'. Current value: 'ngSwitch: undefined'.

我在这里做了一个stackblitz演示(https://stackblitz.com/edit/angular-8to3ra?embed=1&file=src/app/app.component.html)。如果有人指出我做错了,那将是很大的帮助。由于我刚接触Angular,将不胜感激。我的第一个问题是为什么我的父组件无法从服务中获得未定义?第二个问题是未更新父组件中的计数值吗?

angular angular-services
1个回答
1
投票

您的“ your-data.component.html”中有任何错误。不是吗?

<div [ngSwitch]="count"> <!--you wrote [ngSwitch]=count -->
        <app-census (next)="onNext($event)" *ngSwitchCase="'count1'"></app-census>
        <!--you wrote <app-application ... *ngSwitchCase="getPrev()">-->
        <app-application (next)="onNext($event)" *ngSwitchCase="'count2'">
        </app-application>        
</div>
© www.soinside.com 2019 - 2024. All rights reserved.