-1

我正在从 JSON 加载数据,如果数据不可用,我想重定向到错误页面。

我试过$location.path("404")了,但我总是收到一条错误消息:

“未捕获的类型错误:无法读取未定义的属性‘路径’”。

指示:

myApp.directive("wfDependency", function(countTaskService,WorkflowRuns) {
  return {
    some d3 code in here...
  }
  $scope.$watch("workflowPath", function(wfPath, wfPath_old) {              
    d3.json("json/workflows/"+$scope.workflowPath+".json", function(error, data, $location) {
      if(error){
       console.log("ERROR");
       $location.path("/404");
      }else{
        $scope.data = data;
        createGraph();
      }
    });
  });
}); 

我的应用程序:

let myApp = angular.module("myApp", ["ngRoute", "ngResource"])
  .config(function($routeProvider) {
    $routeProvider
    .when("/404", {
      templateUrl: "views/404.htm"
    });
  });
4

1 回答 1

1

你忘了注入$location你的指令。

myApp.directive("wfDependency", function($location, countTaskService, WorkflowRuns) ...
于 2019-04-24T09:10:03.307 回答