开发仪表板我发现以下错误,我明白这是因为我错误处理了Angular循环 . 我找到了解决方法但不是真正的解决方案 .

当您按下更新authenticated属性为true的按钮时,我有一个充当全局范围的服务然后在登录屏幕上 .

它成为现实的那一刻我有一个显示 Headers 的 Headers ,该 Headers 存储在全局范围内

在主屏幕上,我更新了全局范围内 Headers 的值 . 那一刻我得到错误ERROR错误:“ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后发生了变化 . 上一个值:'FormTitle:' . 当前值:'FormTitle:Home' . ”

全球范围:

import { Injectable } from '@angular/core';

@Injectable()
export class ScopeService {
  scope: any = {
    FormTitle:"",
    showMenu:false,
    loading:false,
    authenticated:false
  };
}

app.component.html

<div class="container-flow">
    <app-header *ngIf="ScopeService.scope.authenticated [FormTitle]="ScopeService.scope.FormTitle"></app-header>
<app-navigation *ngIf="ScopeService.scope.authenticated"></app-navigation>
<div class="main-container">
    <router-outlet></router-outlet>
</div> 
</div>

header.component.html

<div class="main-header">
    <h1 class="title"> {{ FormTitle }} </h1>
</div>

home.commonent:

import { Component, OnInit } from '@angular/core';
import { ScopeService } from '../../services/scope.service';
import { ApiService } from '../../services/api.service';
import { Router , ActivatedRoute } from "@angular/router";
import { FormBuilder, FormGroup , Validators } from '@angular/forms';



@Component({
    selector: 'app-home',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.scss']
})


export class HomeComponent implements OnInit {
    viewForm: FormGroup; 
  

    constructor(private formBuilder: FormBuilder,
        private ScopeService:ScopeService,
        private ApiService: ApiService,
        private route: ActivatedRoute,
        private router:Router) { }

    ngOnInit() {
        this.ScopeService.scope.FormTitle = this.route.snapshot.data['title'];
    }
}

登录点击事件:

continuar() {
    this.ScopeService.scope.authenticated = true;
    this.router.navigate(['home'],{ skipLocationChange : true }); 
}