猫猫球团团 2023-04-24 14:19 采纳率: 71.4%
浏览 20

帮我把第三部分register.component.ts的代码补全,注释掉的是我写的运行出错的代码,实在没有思路写不出来了,功能就是注册用户,如何解决?

帮我把第三部分register.component.ts的代码补全,要具体代码,注释掉的是我写的运行出错的代码,实在没有思路写不出来了,要具体代码,功能就是注册用户


--------------------------register.service.ts
@Injectable({
    providedIn: 'root',
})
export class RegisterService {
    constructor(private httpClient: HttpClient) { }

    /**
     * 登录
     *
     * @param {string} userName
     * @param {string} password
     * @param {string} email
     * @param {date} birthday
     * @param {string} gender
     * @param {string} grade
     * @param {string} interest
     * @param {string} introduction
     * @param {date} validStartTime
     * 
     * @return {*}  {Observable<HttpResult>}
     * @memberof RegisterService
     */
    public register(userName: string, password: string, email: string,
        birthday:string, gender:string, grade:string, interest:string, 
        introduction:string, validStartTime:string): Observable<HttpResult> {
        return this.httpClient.post<HttpResult>(apiUrl.register, {
            userName: userName,
            password: password,
            email: email,
            birthday: birthday,
            gender: gender,
            grade: grade,
            interest: interest,
            introduction: introduction,
            validStartTime: validStartTime,
        });
    }
}

---------------------------register.model.ts
export interface User {
    userId: number;
    userName: string;
    password: string;
    userType: number;
    email: string;
    birthday: string|null;
    gender: string;
    grade: string;
    interest: string;
    introduction: string;
    validStartTime: string;
}

-------------------------------register.component.ts
export class RegisterComponent {
    constructor(private service: RegisterService, private router: Router) { }

    /**
     * 注册
     *
     * @param {string} userName
     * @param {string} password
     * @param {string} email
     * @param {string} birthday
     * @param {string} gender
     * @param {string} grade
     * @param {string} interest
     * @param {string} introduction
     * @param {string} validStartTime
     * 
     * @memberof RegisterComponent
     */
    public submit(userName: string, password: string, email: string,
        birthday: string, gender: string, grade: string, interest: string,
        introduction: string, validStartTime: string): void {
        // this.errorMessage = null;
        // gender = this.gender;
        // grade = this.grade;

        this.service.register(userName, password, email, birthday, gender, grade,
            interest, introduction, validStartTime).subscribe((result: HttpResult) => {
                // if (result.status !== HttpResultStatus.SUCCESS) {
                //     this.errorMessage = result.errors[0]?.message || '登录失败';
                //     setTimeout(() => this.errorAlert.close(), 2000);
                // } else {
                //     this.result = true;
                //     this.close();
                // }

                ------------------------------------------------------------------







                ---------------------------------------------------------------------
            });


    }


}
  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2023-04-24 15:08
    关注

    报什么错误,代码中用到HttpResultStatus 对象,用下面的语句导入了没用?

    
    import { HttpResultStatus } from '../constants/http-result-status.constant';
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 4月24日