在Agular的英雄官方教程之旅(https://angular.io/tutorial/toh-pt6)
调用addHero方法时,只传递英雄的名字属性,但不知何故会创建一个具有id属性的新英雄对象。 我可能会遗漏一些东西,但是id属性来自哪里?
答案 0 :(得分:1)
此角度应用程序使用angular-in-memory-web-api程序包拦截所有http请求并隐藏一些功能:
protected post(...): ResponseOptions {
const item = this.clone(this.getJsonBody(req));
if (item.id == undefined) {
try {
item.id = id || this.genId(collection, collectionName);
^^^^^^^^^^^^^
generate id