В Angular 8, как я могу использовать атрибут компонента в другом? - PullRequest
0 голосов
/ 15 марта 2020

У меня есть два компонента: скидка пользователя и клиента. Они связаны по совокупности. Как я могу сослаться на Мобильный пользователь в модели Customer Discount и как сделать конечную точку API в сервисе Customer Discount, чтобы использовать мобильный номер пользователя для поиска скидки?

user.model.ts:

export interface User {
  mobile: number;
  username: string;
  email?: string;
  dni?: string;
  address?: string;
  registrationDate?: Date;
  active?: boolean;
  role?: string[];
}

customer-discount.model.ts:


export interface CustomerDiscount {
  id: string;
  description: string;
  registrationDate?: Date;
  discount: number;
  minimumPurchase: number;
}

customer-discount.service.ts:

import {Injectable} from '@angular/core';
import {HttpService} from '../../core/http.service';
import {AppEndpoints} from '../../app-endpoints';
import {CustomerDiscount} from './customer-discount.model';
import {Observable} from 'rxjs';
import {User} from '../users/user.model';

@Injectable()
  export class CustomerDiscountService {

    constructor(private httpService: HttpService) {
    }

    searchByMobile(mobile: number): Observable<User[]> {
      return this.httpService.get(AppEndpoints.CUSTOMER_DISCOUNTS + '/search?mobile=' + mobile);
    }

  }
...