auth.service.ts 633 B

1234567891011121314151617181920
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3. import { Observable } from 'rxjs';
  4. @Injectable({
  5. providedIn: 'root'
  6. })
  7. export class AuthService {
  8. private apiUrl = 'http://localhost:5000'; // 后端 API 地址
  9. constructor(private http: HttpClient) {}
  10. register(username: string, email: string, password: string): Observable<any> {
  11. return this.http.post(`${this.apiUrl}/register`, { username, email, password });
  12. }
  13. login(email: string, password: string): Observable<any> {
  14. return this.http.post(`${this.apiUrl}/login`, { email, password });
  15. }
  16. }