Javascript AmplifyJS状态错误TypeError:无法读取属性';州';未定义的

Javascript AmplifyJS状态错误TypeError:无法读取属性';州';未定义的,javascript,angular,typescript,amplifyjs,Javascript,Angular,Typescript,Amplifyjs,我正在尝试使用Angular cli应用程序在Amplify中实现以下演练。 我的应用程序是在上述演练之后的全新angular cli版本 我的目标是使用上面链接中提到的独立auth组件 我的问题是在尝试添加 我的组件在上面的链接演练中详细说明了所需的状态设置 auth.component.ts import { Component, OnInit } from '@angular/core'; import { AmplifyService } from 'aws-amplify-angu

我正在尝试使用Angular cli应用程序在Amplify中实现以下演练。

  • 我的应用程序是在上述演练之后的全新angular cli版本

  • 我的目标是使用上面链接中提到的独立auth组件

  • 我的问题是在尝试添加

    我的组件在上面的链接演练中详细说明了所需的
    状态设置

    auth.component.ts

    import { Component, OnInit } from '@angular/core';
    import { AmplifyService } from 'aws-amplify-angular';
    
    @Component({
      selector: 'app-auth',
      templateUrl: './auth.component.html',
      styleUrls: ['./auth.component.css']
    })
    export class AuthComponent implements OnInit {
    
      constructor(private amplifyService: AmplifyService) {
        this.amplifyService.setAuthState({
          state: 'signUp',
          user: null
        });
      }
    }
    
    auth.component.html

    <amplify-auth-sign-up></amplify-auth-sign-up>
    
    
    

    非常感谢您的帮助。任何问题/额外信息,请告诉我。

    我能够让它与下面的代码一起工作。关键是放大单个组件需要设置一个状态——我可以使用下面的“authState”进行设置。区别在于除了typescript之外,还明确地在html中指定了状态

    设置authState(user:null,state:'signUp'如下所示)应该足以删除错误并显示注册表单

    在这里的代码中,我还添加了一些项目来演示如何使用authState

    在下面,页面将加载注册表单

    用户输入详细信息并单击注册后,页面将显示“确认注册”表单,用户在其中输入Cognito发送给他的验证码(取决于您的Cognito设置):

    html:

    我为自动登录等功能添加了更多细节


    还要注意的是,我发现放大组件可以向用户显示错误消息,我不希望用户看到这些消息——随机的、技术性的东西。可能有一种自定义方法(一些讨论),但一定要测试许多不同的场景,以了解可能出现的错误消息。

    您找到了答案吗?我也看到了同样的情况。不幸的是没有:(我的代码在我的情况下是有效的。请看下面我的答案。我已经调整了我的代码以匹配类似的情况,页面上没有任何错误,但组件没有加载。)
        <amplify-auth-sign-up [authState]="authState" *ngIf="showSignUp"></amplify-auth-sign-up>
        <amplify-auth-confirm-sign-up [authState]="authState" *ngIf="showVerify"></amplify-auth-confirm-sign-up> 
    
        import { AmplifyService } from 'aws-amplify-angular';
        import { AuthState } from 'aws-amplify-angular/dist/src/providers';
    
        Export class AuthComponent implements OnInit {
    
        public authState: AuthState
        public newUser: any
        public state: any
        public showSignUp = true
        public showVerify = false
    
        constructor(public amplifyService: AmplifyService) {
             this.authState ={ //setting this should be enough to show the sign-up form and remove the error
               user: null,
               state: 'signUp' 
             }
    
             this.amplifyService.setAuthState(this.authState)  //this might not be required
    
             this.amplifyService.authStateChange$ //listening for state changes. For example, if you want to take action after the user has submitted the sign up form
                    .subscribe(authState => {   
                        this.state = authState.state
                        this.newUser = authState.user
                        if (this.newUser){ //just an example of getting data from the stateChange. Not required.
                          this.username = this.newUser.username
                        }
    
                        if (this.state === 'confirmSignUp'){//get change in state
                           this.authState ={
                              user: authState.user,
                             state: 'confirmSignUp'
                           }
                           this.showSignUp = false
                           this.showVerify = true
                        }
                    }
         }
     }