0
我已創建了角4版一個簡單的服務標題列表,我返回數組有幾個頭銜:角 - 得到JSON佔位
下面的代碼:
//post.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class PopstService {
constructor() {}
showPosts() {
return ['title1', 'title2', 'title3'];
}
}
而是有它的硬編碼在服務頁面我想從一些JSON數據中翻譯標題。
這裏的網址:
https://jsonplaceholder.typicode.com/posts
的數據是這樣的:
0
userId 1
id 1
title "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
body "quia et suscipit\nsuscip… rem eveniet architecto"
1
userId 1
id 2
title "qui est esse"
body "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
我怎麼能修改此服務從網上JSON,而不是我目前硬編碼的標題返回的標題?
https://angular.io/guide/http – JEMI