typescript - 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'}]
解决方案
推荐阅读
- c# - 如何在 C# 中使用动态和静态键名反序列化 JSON
- concurrency - AWS Lambda 时间负载均衡
- swift - 使用 ARKit 3.0 在 iPhone XR 上进行人物分割
- iis - 如何将所有 IIS 设置、配置、应用程序池从一个 IIS 框复制到另一个?
- .net - JWT 令牌签名在 jwt.io 中有效,但在我的代码中无效
- javascript - JavaSctript Promise.all 在地图上
- angular - Angular Breadcrumb 显示用户到达当前页面的路径
- django - DateTimeField 到 str 并从 str 读取
- python - subprocess + service network-manager 是禁用网络的好方法吗?
- tensorflow - 替换tensorflow 2.0中损失函数的梯度计算