Angularjs中$location的Url重定向问题-无法读取property 'path'的定义
Issue with Url redirect on $location in Angularjs - Cannot read property 'path' of undefined
我是AngularJS的新手,我试图运行这个AngularJS,当我点击提交按钮时,应该修改URL而不重新加载页面,但在控制台上,我得到TypeError:无法读取属性'path'的undefined
真的看不出我错过了$location注入。有什么问题吗?
var app = angular.module("SearchAPP", ['ngRoute']);
app.run(['$route', '$rootScope', '$location',
function($route, $rootScope, $location) {
var original = $location.path;
$location.path = function(path, reload) {
if (reload === false) {
var lastRoute = $route.current;
var un = $rootScope.$on('$locationChangeSuccess', function() {
$route.current = lastRoute;
un();
});
}
return original.apply($location, [path]);
};
}
]);
app.controller('GetController', ['$http', '$scope', '$location',
function($http, $scope, $rootScope, $location) {
$scope.click = function() {
var response = $http({
url: 'http://localhost:4567/search',
method: "GET",
params: {
keyword: $scope.searchKeyword
}
});
response.success(function(data, status, headers, config) {
$scope.searchResults1 = data;
// $http.defaults.useXDomain = true;
$location.path('/' + $scope.searchKeyword, false);
});
response.error(function(data, status, headers, config) {
alert("Error.");
});
};
}
]);
DI数组依赖顺序错误,DI数组第三个参数缺少$rootScope
。确保注入的依赖项在控制器函数
// VVVVVVVV $rootscope was missing
app.controller('GetController', ['$http', '$scope', '$rootScope','$location',
function($http, $scope, $rootScope, $location) {
相关文章:
- Phonegap错误-无法读取property 'capture'undefined"在And
- 不能读取property 'top'未定义的Ruby on Rails项目
- 不能读取property ' rotate '未定义的动力学
- 无法读取property 'canvas'的定义
- 显示错误无法读取property 'style'的定义
- 无法读取property 'length'在旁边的未定义的
- 无法读取property 'value'形式中未定义的错误
- 无法读取property 'length'vt .扩展;扩展;
- 不能读取property 'slice'在WordPress上应用carousel from boots
- 无法读取property 'bind'的定义
- 错误:无法读取property 'props'在Child中调用父方法
- 无法读取property 'length'在json中使用游标时未定义
- Angular JS:不能读取property 'then'的定义
- Javascript无法读取property '零
- 不能读取property 'Store'使用RedisStore和Node.js
- React -不能读取property '的定义
- Jquery Unobtrusive Validation '无法读取property 'type
- 无法读取property 'finally'的定义
- Autolinker.js的问题:无法读取property 'assign'的定义
- 无法读取property 'run'的定义