在组件中更新数据后,使用解析器在子组件中加载数据

问题描述

我有一个角度为'update_profile'的组件,该组件使用解析器服务加载数据。

我还在使用选择器在另一个组件“ complete_profile”中调用“ update_profile”。当需要编辑时,我通过ngIf来初始化组件。

为了能够在“ complete_profile”中加载数据,我还将解析器注入了父组件。

const routes: Routes = [
  {
    path: "",component: OrganiserLayoutComponent,children: [
      { 
        path: "complete_profile",component: MyProfileComponent,resolve: { profileDetails: UpdateProfileResolverService } 
      },{
        path: "update_profile",component: UpdateProfileComponent,resolve: { profileDetails: UpdateProfileResolverService },},],];

@NgModule({
  imports: [RouterModule.forChild(routes)],exports: [RouterModule],})

update_profile组件

ngOnInit() {
    this.dataSubscription = this.activatedRoute.data.subscribe(
    (data: { profileDetails: any }) => {
      this.profileData = data.profileDetails["data"];
      console.log(this.profileData);
      },);
}

解析器服务

import { Injectable } from '@angular/core';
import { Resolve,RouterStateSnapshot,ActivatedRouteSnapshot } from '@angular/router';
import { AppServiceService } from './../../../common/services/app-service.service';
import { AuthServiceService } from './../../../common/services/auth-service.service';

@Injectable({providedIn:'root'})
export class UpdateProfileResolverService implements Resolve<any> {
  constructor(public appService: AppServiceService,public auService: AuthServiceService) {}

  resolve(route: ActivatedRouteSnapshot,state: RouterStateSnapshot){
    let currentUser;
    this.auService.User.subscribe(user=>{
      if(user){
        currentUser=user.token;
      }
    }).unsubscribe();
    return this.appService.getParams2('/organizer/',currentUser.Id);
  }
}

update_profile在complete_profile中被调用

<app-update-profile *ngIf="isShown"></app-update-profile>

当我要进行update_profile路由时,我的数据始终会更新..没关系。 但是在complete_profile组件中,通过在update_profile选择器上应用ngIf指令来显示update_profile,并且每当我单击一个按钮以提供真实条件以显示complete_profile组件内部的update_profile组件时,数据就不会更新。它显示了解析器在complete_profile初始化时检索到的先前数据。

我知道解析器仅在更改路由时解析数据。但是无论何时初始化update_profile组件,我都需要解析的更新数据。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)