import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class AuthService { private apiUrl = 'http://localhost:5000'; // 后端 API 地址 constructor(private http: HttpClient) {} register(username: string, email: string, password: string): Observable { return this.http.post(`${this.apiUrl}/register`, { username, email, password }); } login(email: string, password: string): Observable { return this.http.post(`${this.apiUrl}/login`, { email, password }); } }