Ess*_*diM 2 json typescript angular angular7
我如何告诉 Angular 在 http 调用之前忽略一个或多个字段;就像@JsonIgnorejava中的一样。
例子:
我有这个对象:{id: 1, libelle: 'test', mustIgnore: 'test'};
我希望这个对象是:{id: 1, libelle: 'test'};
我尝试过delete object.field,但我正在寻找一种更简单的方法来做到这一点,例如在我的对象上使用注释。
因为如果我有一个对象数组,管理它就会变得更加困难。
编辑 :
我不想为每个对象手动执行此操作!有没有一种方法可以指定我想要删除的字段,并在每当我有一个具有不同字段的不同对象要删除时自动执行此操作
使用 ES6object destructuring获取没有所需属性的不可变对象。
const obj = {id: 1, libelle: 'test', mustIgnore: 'test'};
// Destructure into mustIgnore and rest properties
const { mustIgnore, ...rest } = obj;
const projectedObject = rest;
console.log("old", obj);
console.log("new", projectedObject);Run Code Online (Sandbox Code Playgroud)