【问题标题】:How to make Angularjs $http.delete and asp.net mvc4 minification work together?如何使 Angularjs $http.delete 和 asp.net mvc4 缩小一起工作?
【发布时间】:2013-03-21 08:37:51
【问题描述】:

我正在开发一个 AngularJs/asp.net mvc4 应用程序,该应用程序通过 asp.net mvc web api 与后端通信。

javascript 文件的缩小是用 mvc4 完成的,但是当我在 Angular 代码中使用 $http.delete 时,mvc4 minifyer 在捆绑文件中返回以下错误:

/* Minification failed. Returning unminified contents.
(1029,11-17): run-time warning JS1010: Expected identifier: delete
(1029,11-17): run-time error JS1137: 'delete' is a new reserved word and should not be used as an identifier: delete

我已经完成了替换保留字(在本例中为“删除”)的解决方法,此处描述为 https://stackoverflow.com/a/13418911/1029874

这意味着$http.delete将被替换为$http.fooDelete,导致angular不再识别它。

是否有其他解决方法或者是使用 jQuery ajax 的最简单解决方案?

【问题讨论】:

  • 使用$http['delete']() 并且在AngularJS中尽量不要使用jQuery ajax。

标签: asp.net-mvc-4 angularjs bundling-and-minification


【解决方案1】:

@larchii 使用 $http'delete' 作为@stewie 提到的。根据this article,使用任何 IE 保留字都会导致引发预期的标识符错误。还有一个指向 IE 保留字列表的链接。希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我有同样的问题,但我的解决方法是这样做而不是使用快捷方式:

    $http({method: 'DELETE', url: '/someUrl'}).
      success(function(data, status, headers, config) {
        // this callback will be called asynchronously
        // when the response is available
      }).
      error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
      });
    

    【讨论】:

      猜你喜欢
      • 2013-02-01
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 2014-01-03
      相关资源
      最近更新 更多