【问题标题】:How to stop Angular 6 from sanitizing json payload如何阻止 Angular 6 清理 json 有效负载
【发布时间】:2018-06-21 19:14:27
【问题描述】:

我最近将我的 Angular 项目从 4.2 版升级到了 6 版。一切都很好,除了我注意到 Angular 现在在发出发布请求时从我的 json 有效负载中删除了函数(这可能也发生在其他 http 选项中,但没有'没有检查他们)。除了 json.stringify 之外,有没有办法禁用此功能或解决方法?

这是我要发布的 json 有效负载:

{
  name: "ghq_employeesTotal", 
  fieldMapping: ['item1'], 
  translation: ƒunction(val){ return val.toLowerCase()}
}

这是我在网络选项卡中看到的有效负载:

{
  name: "ghq_employeesTotal", 
  fieldMapping: ['item1']
}

如您所见,它完全删除了我的翻译属性。

这是我发送帖子请求的函数:

public publishConfig(config): Observable<any>{
  return this.http.post<any>(this.serviceURL + 'publish', config);
}

【问题讨论】:

    标签: json angular angular6


    【解决方案1】:

    ƒunction(val){ return val.toLowerCase()} 不是有效的 JSON 数据类型。

    JSON 仅支持数组、对象和原始值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多