0

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

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

应用程序.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
app/workorder/workOrderListView.html 在 $httpBackend (angular-mocks.js:1403) 处不再有请求

4

1 回答 1

0

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

将此添加到运行方法的末尾,

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

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

于 2016-04-08T04:09:38.860 回答