【发布时间】:2016-10-07 21:51:04
【问题描述】:
我很喜欢问类似的问题,但无法解决我的问题。
@Component({
selector: 'waiting',
template: `
<div class="waiting">
<div *ngIf="isLoading" class="loader2"></div>
<div>`
})
export class WaitingComponent {
public isLoading: boolean;
public constructor(private _authHttp: HttpService) {
this._authHttp.request.subscribe((action: HttpAction) => {
this.isLoading = action === HttpAction.Requested;//HttpAction.Requested returns 0 or 1
});
}
}
我看到有人建议必须在 AfterViewInit 中更改值 isLoading。我不知道如何使它工作。提前致谢。
【问题讨论】:
-
此代码不应导致该错误。必须有别的东西。
-
this.isLoading = action === HttpAction.Requested;感觉这条线有问题。 -
这个
this.isLoading = HttpAction.Requested怎么样? -
@micronyks
this.isLoading = HttpAction.Requested将返回和异常,因为 HttpAction.Requested 的返回值是数字,0 或 1。this.isLoading = action === HttpAction.Requested;工作正常,没有问题。 -
@GünterZöchbauer 不幸得到
inline template:2:9 caused by: Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.
标签: angular typescript