English 中文(简体)
A. 形式价值不明或空洞
原标题:Form value is undefined or empty Angular 14

我正在拿到形式上未定义的形式价值。


   @ViewChild( someForm , { static: true }) form: ElementRef<HTMLFormElement>;
   public apiReponse: JsonResponse;
   this.route.queryParams
           .pipe(
               switchMap((params) =>
                   this.authService.getToken$(
                     param1, param2
                   )
               ),
               first(),
               takeUntil(this.ngUnsubscribe$)
           )
          .subscribe({
               next: (returnJson) => {
                   const responseObj = JSON.parse(returnJson);
                   this.apiReponse = responseObj;
                   console.log( response , this.apiReponse);
                   console.log( this form , this.form.nativeElement);
                   this.form.nativeElement.submit();
               },
               error: () => {
                   console.log( Some error  );
               },
           });

我的发言

  <form
   #someForm
   ngNoForm
   method="post"
   enctype="application/x-www-form-urlencoded"
    >
   <input type="hidden" id="token" name="token" [value]="apiReponse?.token" />
    </form>
   ```
问题回答

I have faced this kind of issue earlier and adding the submit() in setTime out worked.

subscribe({
    next: (returnJson) => {
      const responseObj = JSON.parse(returnJson);
      this.apiResponse = responseObj;
      console.log( response , this.apiResponse);
      console.log( this form , this.form.nativeElement);
      setTimeout(() => {
        this.form.nativeElement.submit();
      }, 100); 
    },




相关问题
Angular matSort not working on Date column by desc

Trying to sort the material table with date column , date format is MM/DD/YYYY ,h:mm A , order of date is not by latest date and time. Anything which i missed from the below stackblitz code. https:/...

热门标签