Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:$location.path不是函数_Javascript_Html_Angularjs - Fatal编程技术网

Javascript TypeError:$location.path不是函数

Javascript TypeError:$location.path不是函数,javascript,html,angularjs,Javascript,Html,Angularjs,这是我的剧本。 错误是。 如果要执行此操作,需要在控制器中注入$location。您缺少作为参数的“焦点” $scope.itemOpen=function() { return $location.path('/ConsultationParameterMaster'); }; 编辑: 根据您的评论,您需要安排依赖项 app.controller('sampleController', ['$scope','$http','$l

这是我的剧本。 错误是。

如果要执行此操作,需要在控制器中注入$location。您缺少作为参数的“焦点”

 $scope.itemOpen=function()
         {
             return $location.path('/ConsultationParameterMaster');
         };
编辑:

根据您的评论,您需要安排依赖项

app.controller('sampleController', ['$scope','$http','$location', function($scope,$http,$location) {
 $scope.itemOpen=function()
         {
             return $location.path('/ConsultationParameterMaster');
         };
}

控制器应将
$location
作为参数。如果忘记注入
$location
,显然无法使用它。

在定义角度控制器的javascript中,需要为
$location
注入依赖项,如下所示:

coreModule.registerController('MedicalRecordsController', ['$rootScope', '$scope', '$sessionStorage', 'Restangular', '$element', '$themeModule', '$filter', '$uibModal', 'gettext', 'focus', '$location', function ($rootScope, $scope, $sessionStorage, Restangular, $element, $themeModule, $filter, $uibModal, gettext,focus,$location)

您的依赖项排列不正确。您在依赖项列表中有
'focus'
,但在参数列表中没有,因此您的
$location
实际上是
focus
。这就是为什么它没有
.path()
方法的原因

要修复此问题,请将焦点添加到参数中:

app.controller('myCtrl', ['$scope', '$location', function($scope, $location) {
    ...
}
$modal,gettext,/*-->*/focus/*
app.controller('ctrl'、['$http'、'$scope'、'$location',函数($http、$scope、$location){
$scope.itemOpen=function()
{
返回$location.path('/ConsultationParameterMaster');
};
}

您是否在控制器中注入了$location?coreModule.registerController('MedicalRecordsController'、['$rootScope'、'$scope'、'$sessionStorage'、'Restanglar'、'$element'、'$themeModule'、'$filter'、'$uibModal'、'gettext'、'focus'、'$location'函数($rootScope、$scope、$sessionStorage、restanglar、$element、$theme、$filter、$model、gettext、$location、,
app.controller('myCtrl', ['$scope', '$location', function($scope, $location) {
    ...
}
$modal, gettext, /*-->*/focus/*<--*/, $location)