将 JSON 数据推入对象数组 ANGULAR
Pushing JSON data into array of objects ANGULAR
private contacts: Array < Contact > = [{
first_name: "Darko",
last_name: "Lesevic",
email: ["darko@test.com", "najjaci@test.com"],
phone: [123456789, 123456789, 123456789],
photo: "",
id: 1
}, ];
getContactsJSON(): Observable < IContact[] > {
return this.http.get < IContact[] > ("/assets/data/contacts.json");
};
//I want to combine these two
getAllContacts(): Observable < IContact[] > {
return of(this.contacts);
};
我想将 JSON 数据放入联系人数组,因为我正在制作 CRUD 应用程序,但不知道如何,请帮助我。 Here is my photo and here is my JSON data and class。我想保留来自 JSON 和我自己的 class 的数据,这可能吗?
可以订阅您的 API 请求并将结果应用于您的数组:
this.getContactsJSON.subscribe(s=> {
this.contacts = s;
console.log(this.contacts); // you can check your array `this.contacts`
})
private contacts: Array < Contact > = [{
first_name: "Darko",
last_name: "Lesevic",
email: ["darko@test.com", "najjaci@test.com"],
phone: [123456789, 123456789, 123456789],
photo: "",
id: 1
}, ];
getContactsJSON(): Observable < IContact[] > {
return this.http.get < IContact[] > ("/assets/data/contacts.json");
};
//I want to combine these two
getAllContacts(): Observable < IContact[] > {
return of(this.contacts);
};
我想将 JSON 数据放入联系人数组,因为我正在制作 CRUD 应用程序,但不知道如何,请帮助我。 Here is my photo and here is my JSON data and class。我想保留来自 JSON 和我自己的 class 的数据,这可能吗?
可以订阅您的 API 请求并将结果应用于您的数组:
this.getContactsJSON.subscribe(s=> {
this.contacts = s;
console.log(this.contacts); // you can check your array `this.contacts`
})