javascript - 发布 - 角 5
问题描述
我对 Angular 还很陌生,并且一直无法从后端的 SpringREST 获取数据。所以场景是:我JSON
将从后端获取一个字符串POST
(JSON 数据将作为 POST 重定向到我的站点托管链接),我需要捕获该 JSON 字符串并将其显示在 UI 上。我不确定postMethod
in dataservice.ts 是否应该存在。
我在 stackoverflow 上搜索并想出了以下代码,这在我的场景中似乎不起作用:
组件.ts
import { MyDataService } from './services/my-data.service';
constructor(private posting: MyDataService
) {}
ngOnInit() {
this.posting.postMethod().subscribe(
(response => {
console.log(response)
}));
}
}
数据服务.ts
@Injectable()
export class MyDataService {
constructor(private http: Http)
{ }
postMethod(model: any ) {
return this.http.post("http ://", model)
.map(res => res.json());
}
}
解决方案
正如错误所说,您需要在调用时将参数传递给服务
this.posting.postMethod(model).subscribe(
(response => {
console.log(response)
}));
推荐阅读
- sql - SQL Count 与按问题分组不同
- asp.net-core - ASP .Net Core 中的图像压缩而不降低图像质量
- git - ChefSpec 找不到安装的 git
- python - 我什么时候应该在 pandas 数据帧上使用 query vs eval?
- c - 将 printf 命令写入或保存到文本文件(c 编程)
- node.js - 同一行 Node.js 代码可以同时运行吗?
- java - java - 如何在java中使用useDelmeter从字符串中获取两个特定值?
- spring-boot-actuator - 如何自定义 Spring Boot admin 2.o UI?
- c - 从 16 位架构中的给定索引计算位掩码
- r - 有条件的按组计数(在 R data.table 中)