首页 > 解决方案 > Angular 6地图不起作用

问题描述

我想制作一个地图并从返回后端的数据数组中创建一个新的对象数组,但我总是返回一个对象。现在我不致力于价值,但我应该返回一个空对象矩阵

//brand.ts
export class Brand {
 id : number;
 name : string;
 description : string;
 picture : string;
 provider : string;

 constructor() {
 }
}

// brand.service
 import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.stage';
import { Brand } from '../../models/brand';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
export class BrandService {
  constructor(private http: HttpClient) {

  }

  getBrands() {
    return this.http.get<any[]>(`${environment.apiUrl}brands`).pipe(
      map((a) => new Brand)
    );
  }
}

// method of component 
this.brandService.getBrands().subscribe((brands) => {
      console.log(brands);
    });

//data of back-end
[{id: 1, name: 'ssds', description: 'dsds', provider:'sds'}]

标签: typescriptrxjsangular6

解决方案


推荐阅读