angularjs – $httpBackend .whenGet不是Angular中的函数

前端之家收集整理的这篇文章主要介绍了angularjs – $httpBackend .whenGet不是Angular中的函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用虚拟服务来获取Angular中的数据,我正在使用ngMockE2E,而我的Mock代码如下所示:
(function () {
    "use strict"
    var app = angular
        .module("productResourceMock",["ngMockE2E"]);

    app.run(function ($httpBackend) {
       var products = [
           {
               "productId": 1,"productName": "mobile1","productCode": "heh4","releaseDate": "May 21,2013","description": "very nice mobile","cost": 200,"price": 300,"category": "Electronics","tags": ["mobile","electronic"],"imageUrl": "images/img1.jpg"
           },{
               "productId": 2,"productName": "mobile2",2012","description": "not a nice mobile","cost": 100,"price": 500,"Electronic"],"imageUrl": "images/img2.jpg"
           }];

        var productUrl = "/api/products";
        $httpBackend.whenGet(productUrl).respond(products);
    });

}());

我已经定义了我的控制器,在里面,它有这个代码

(function () {
    "use strict"
    angular
        .module("productManagement")
        .controller("ProductListCtrl",["productResource",ProductListCtrl]);

    function ProductListCtrl(productResource) {
        var vm = this;
        productResource.query(function(data){
         vm.products = data;
        });
    }
}());

对于我发送REST请求的服务,我有这样的代码

(function () {
    "use strict"
    angular
        .module("common.services")
        .factory("productResource",["$resource",productResource]);


    function productResource($resource) {
        return $resource("/api/products/:productId");
    }
}());

我仍然收到此错误:未捕获TypeError:$httpBackend.whenGet不是一个函数.

如有任何帮助,或需要任何澄清,请告诉我.

答案很简单:用whenGET时取代

小心将http动词全部写成大写.

ngMock documentation

原文链接:https://www.f2er.com/angularjs/141222.html

猜你在找的Angularjs相关文章