ui路由角度返回意外请求:GET

时间:2016-04-08 03:43:46

标签: angularjs angular-ui-router ngmocke2e

下面是我的角度项目的ui路由设置。我无法打开工作单列表页面。我不确定以下设置有什么问题,请您告诉我如何打开工作单列表页面来查看我的工单。

在浏览器上调用的网址 http://localhost:63342/vdash/index.html#/workorders

app.js

(function () {
"use strict";
var app = angular.module("workOrderManagement", ["common.services",      "ui.router", "workOrderResourceMock"]);
app.config(["$stateProvider", "$urlRouterProvider", function ($stateProvider, $urlRouterProvider) {
        $urlRouterProvider.otherwise("/workorders");

        $stateProvider.state("workOrderList", {
            url: "/workorders",
            templateUrl: "app/workorder/workOrderListView.html",
            controller: "workOrderCtrl as vm"
        })
    }]
)
})();

workOrderResourceMock.js

(function () {
"use strict";

var app = angular.module("workOrderResourceMock", ["ngMockE2E"]);
app.run(function ($httpBackend) {
    var workOrders = [
        {
            "orderNo": "WO-0000001",
            "city": "San Jose",
            "bank": "Citi Bank",
            "branch": "Maxrk",
            "creationDate": "2017-10-01",
            "clientName": "Mr.Peter",
            "status": "PENDING",
            "handledBy": "Peter",
        }           
    ];

    var workOrderUrl = "/workorders";

    $httpBackend.whenGET(workOrderUrl).respond(function(method, url, data){
      // just to see if it his this function will remove later
        alert("into the backend method");
        console.log(url);


        return [200, workOrders];
    });

$httpBackend.whenGET("/").passThrough();
   });
}());

错误     angular.js:13236错误:意外请求:GET
    应用程序/工作单/ workOrderListView.html     没有更多的要求     在$ httpBackend(angular-mocks.js:1403)

1 个答案:

答案 0 :(得分:0)

Angular正在尝试获取需要显示视图的模板。我假设这是E2E测试。在运行测试时,所有调用都通过$ httpBackend,所以你需要让$ httpBackend允许调用来获取模板。

将其添加到run方法的末尾,

$httpBackend.whenGET("/app/workorder/workOrderListView.html").passThrough();

作为替代解决方案,您可以使用$templateCache来缓存模板,因此angular不必从服务器加载它。