Angular Ng反射值不为空,但输入显示我的占位符,而不是输入值(角度材质)

Angular Ng反射值不为空,但输入显示我的占位符,而不是输入值(角度材质),angular,forms,angular-material,angular9,Angular,Forms,Angular Material,Angular9,尽管ng reflect value不是空的,但我的值没有显示在我的表单中,我不知道它为什么不起作用。 我在另一个组件中使用了相同的过程,它在那里工作,但在这里不工作,我不明白为什么。你能帮我吗 组成部分 import { Component, OnInit, Inject } from "@angular/core"; import { BreakpointObserver, Breakpoints } from "@angular/cdk/layout"

尽管ng reflect value不是空的,但我的值没有显示在我的表单中,我不知道它为什么不起作用。 我在另一个组件中使用了相同的过程,它在那里工作,但在这里不工作,我不明白为什么。你能帮我吗

组成部分

import { Component, OnInit, Inject } from "@angular/core";
import { BreakpointObserver, Breakpoints } from "@angular/cdk/layout";
import { Observable } from "rxjs";
import { map, shareReplay } from "rxjs/operators";
import { AuthService } from "../_services/auth.service";
import { AlertifyService } from "../_services/alertify.service";
import { Router } from "@angular/router";
import { Userforlogin } from "../_models/userforlogin";
import { JwtHelperService } from "@auth0/angular-jwt";
import { environment } from "src/environments/environment";
import { UserService } from "../_services/user.service";
import { MatDialogConfig, MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { User } from '../_models/user';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';

@Component({
  selector: "app-main-nav",
  templateUrl: "./main-nav.component.html",
  styleUrls: ["./main-nav.component.css"],
})
export class MainNavComponent {
  isHandset$: Observable<boolean> = this.breakpointObserver
    .observe(Breakpoints.Handset)
    .pipe(
      map((result) => result.matches),
      shareReplay()
    );

  jwtHelper = new JwtHelperService();
  baseTitle = environment.title;
  userfl: Userforlogin;

  constructor(
    private breakpointObserver: BreakpointObserver,
    public authService: AuthService,
    private alertify: AlertifyService,
    private router: Router,
    public dialog: MatDialog,
  ) {}

  ngOnInit() {
    this.authService.currentUserTest1.subscribe(
      (userRD) => (this.userfl = userRD)
    );
    const token = localStorage.getItem("token");
    const user: Userforlogin = JSON.parse(localStorage.getItem("user"));
    if (token) {
      this.authService.decodedToken = this.jwtHelper.decodeToken(token);
    }
    if (user) {
      this.userfl = user;
    }
  }

  loggedIn() {
    return this.authService.loggedIn();
  }

  logout() {
    localStorage.removeItem("token");
    localStorage.removeItem("user");
    this.authService.decodedToken = null;
    this.authService.currentUser = null;
    this.alertify.message("Déconnecté");
    this.router.navigate(["/login"]);
  }

  openUserManagementDialog(user: Userforlogin) {
    const dialogConfig = new MatDialogConfig();    

    dialogConfig.width=  '500px';
    dialogConfig.data = {
      user : user       
    };

    const dialogRef = this.dialog.open(DialogUserManagementComponent, dialogConfig);

    dialogRef.afterClosed().subscribe((result) => {
      if (result) {
        
      }
    });
  }
}



@Component({
  selector: "dialog-user-management",
  templateUrl: "dialog-user-management.html",
})
export class DialogUserManagementComponent {
  formGroup: FormGroup; 
  post: any = "";
  userfl: Userforlogin;
  userID: number;

  constructor(
    private userService: UserService, 
    private formBuilder: FormBuilder,
    private dialogRef: MatDialogRef<DialogUserManagementComponent>, 
    @Inject(MAT_DIALOG_DATA) public data: any){
    this.userfl = data.user;
  }

  ngOnInit(): void {  
    this.createForm();
    
  }

  createForm() {
    this.formGroup = this.formBuilder.group({
      firstname: [null, [Validators.required]],  
      lastname: [null, [Validators.required]],  
      login: [null, [Validators.required]],  
      email: [null, [Validators.required]],    
      validate: "",
    });
  }

  onSubmit(post: any){

  }
 


}
import{Component,OnInit,Inject}来自“@angular/core”;
从“@angular/cdk/layout”导入{breakpoint observer,Breakpoints}”;
从“rxjs”导入{observeable};
从“rxjs/operators”导入{map,shareReplay};
从“./_services/auth.service”导入{AuthService}”;
从“./_services/alertify.service”导入{AlertifyService}”;
从“@angular/Router”导入{Router}”;
从“./_models/Userforlogin”导入{Userforlogin}”;
从“@auth0/jwt”导入{JwtHelperService};
从“src/environments/environment”导入{environment};
从“./_services/user.service”导入{UserService}”;
从“@angular/material/DIALOG”导入{MatDialogConfig,MatDialogRef,MAT_DIALOG_DATA};
从“../\u models/User”导入{User};
从'@angular/forms'导入{FormGroup,FormBuilder,Validators};
@组成部分({
选择器:“应用程序主导航”,
templateUrl:“./main nav.component.html”,
样式URL:[“/main nav.component.css”],
})
导出类主导航组件{
isHandset$:Observable=this.Observable
.观察(断点.手持设备)
.烟斗(
映射((result)=>result.matches),
shareReplay()
);
jwtHelper=新的JwtHelperService();
baseTitle=environment.title;
userfl:Userforlogin;
建造师(
私有断点观察者:断点观察者,
公共authService:authService,
私有alertify:AlertifyService,
专用路由器:路由器,
公共对话:MatDialog,
) {}
恩戈尼尼特(){
this.authService.currentUserTest1.subscribe(
(userRD)=>(this.userfl=userRD)
);
const token=localStorage.getItem(“token”);
const user:Userforlogin=JSON.parse(localStorage.getItem(“用户”);
如果(令牌){
this.authService.decodedToken=this.jwtHelper.decodeToken(令牌);
}
如果(用户){
this.userfl=用户;
}
}
loggedIn(){
返回此.authService.loggedIn();
}
注销(){
localStorage.removietem(“令牌”);
localStorage.removietem(“用户”);
this.authService.decodedToken=null;
this.authService.currentUser=null;
这个.alertify.message(“Déconnecté”);
this.router.navigate([“/login”]);
}
openUserManagementDialog(用户:Userforlogin){
const dialogConfig=new MatDialogConfig();
dialogConfig.width='500px';
dialogConfig.data={
用户:用户
};
const dialogRef=this.dialog.open(DialogUserManagementComponent,dialogConfig);
dialogRef.afterClosed().subscribe((结果)=>{
如果(结果){
}
});
}
}
@组成部分({
选择器:“对话框用户管理”,
templateUrl:“dialog user management.html”,
})
导出类DialogUserManagementComponent{
formGroup:formGroup;
post:any=“”;
userfl:Userforlogin;
userID:number;
建造师(
私有用户服务:用户服务,
私有formBuilder:formBuilder,
私有dialogRef:MatDialogRef,
@注入(MAT_对话框_数据)公共数据:任意){
this.userfl=data.user;
}
ngOnInit():void{
这个.createForm();
}
createForm(){
this.formGroup=this.formBuilder.group({
firstname:[null,[Validators.required]],
lastname:[null,[Validators.required]],
登录:[null,[Validators.required]],
电子邮件:[null,[Validators.required]],
验证:“”,
});
}
onSubmit(post:any){
}
}
看法

Modifier mon compte
这是我的要求
名字是什么
需要登录吗
电子邮件是必需的
{{userfl | json}}
环空器
查克·索弗
非常感谢您的帮助和建议!:-)

<h2 mat-dialog-title>Modifier mon compte</h2>
<mat-dialog-content class="mat-typography">  
  <div>    
        <form
          [formGroup]="formGroup"
          (ngSubmit)="onSubmit(formGroup.value)"          
          class="form"
        >
          <mat-form-field class="form-element">
            <input
              matInput
              placeholder="Prénom"
              formControlName="firstname"
              value="{{ userfl?.firstname }}"
            />
            <mat-error
              *ngIf="
                !formGroup.controls['firstname'].valid &&
                formGroup.controls['firstname'].touched
              "
              >Le prénom est requis
            </mat-error>
          </mat-form-field> 
          <mat-form-field class="form-element">
            <input
              matInput
              placeholder="Nom"
              formControlName="lastname"
              value="{{ userfl?.lastname }}"
            />
            <mat-error
              *ngIf="
                !formGroup.controls['lastname'].valid &&
                formGroup.controls['lastname'].touched
              "
              >Le nom est requis
            </mat-error>
          </mat-form-field>     
          <mat-form-field class="form-element">
            <input
              matInput
              placeholder="Login"
              formControlName="login"
              value="{{ userfl?.login }}"
            />
            <mat-error
              *ngIf="
                !formGroup.controls['login'].valid &&
                formGroup.controls['login'].touched
              "
              >Le login est requis
            </mat-error>
          </mat-form-field>     
          <mat-form-field class="form-element">
            <input
              matInput
              placeholder="Email"
              formControlName="email"
              value="{{ userfl?.email }}"
            />
            <mat-error
              *ngIf="
                !formGroup.controls['email'].valid &&
                formGroup.controls['email'].touched
              "
              >L'email est requis
            </mat-error>
          </mat-form-field>         
        </form>    
        
        <div>
            {{ userfl | json }}
        </div>
         
  </div>
 
</mat-dialog-content>
<mat-dialog-actions align="end">
    <button mat-button mat-dialog-close>Annuler</button>
    <button mat-button [mat-dialog-close]="true" cdkFocusInitial mat-raised-button color="primary">
        <mat-icon>check</mat-icon> Sauver
    </button>
</mat-dialog-actions>