我是棱角分明的初学者,并且在复数视线上学习它。在学习期间,我正在开发小型应用程序。但我得到的错误如下,无法追踪它。请帮忙。
错误:
angular.js:11706 TypeError: $q.resolve is not a function
at commitRoute (angular-route.js:716)
at Scope.$broadcast (angular.js:14889)
at afterLocationChange (angular.js:11550)
at angular.js:11536
at Scope.$eval (angular.js:14570)
at Scope.$digest (angular.js:14386)
at Scope.$apply (angular.js:14675)
at bootstrapApply (angular.js:1458)
at Object.invoke (angular.js:4219)
at doBootstrap (angular.js:1456)
申请代码:
app.js
(function() {
var app = angular.module("githubViewer", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/main", {
templateUrl: "main.html",
})
.otherwise({
redirectTo: "/main"
});
});
}());
github.js
var github = function($http) {
var getUser = function(username) {
return $http.get("https://api.github.com/users/" + username)
.then(function(response) {
return response.data;
});
};
var getRepos = function(user) {
return $http.get(user.repos_url)
.then(function(response) {
return response.data;
});
};
return {
getUser: getUser,
getRepos: getRepos
};
};
var module = angular.module('githubViewer');
module.factory("github", github);
的index.html
<!DOCTYPE html>
<html ng-app="githubViewer">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.3.x"
src="https://code.angularjs.org/1.3.20/angular.js" data-semver="1.3.20">
</script>
<script data-require="angular-route@*" data-semver="1.6.2"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular-
route.js"></script>
<script src="app.js"></script>
<script src="MainController.js"></script>
<script src="github.js"></script>
</head>
<body>
<h1>Github Viewer</h1>
<div ng-view></div>
</body>
</html>
main.html中
<div>
<form name="searchUserForm">
<input type="search" placeholder="Enter user to find" />
<input type="submit" value="Search" />
</form>
</div>
MainController.js
var app = angular.module("githubViewer");
app.controller("MainController", function($scope) {
$scope.searchUser = function(username) {
//pl
};
});
UserDetails.js
var app = angular.module('githubViewer');
app.controller('UserController', function($scope, $http,github) {
var onUserComplete = function(data) {
$scope.user = data;
github.getRepos($scope.user).then(onRepos, onError);
};
var onRepos = function(data){
$scope.repos = data;
}
$scope.username = 'angular';
$scope.repoSortedOrder ='-stargazers_count';
var onError = function(reason) {
$scope.error = "Could not fetch the data";
}
$scope.searchUser = function(username) {
github.getUser(username).then(onUserComplete, onError);
};
});
请帮助解决上述问题。
答案 0 :(得分:0)
我遵循相同的教程,我遇到了同样的错误。我通过确保路由模块与该教程(<script data-require="angular-route@*" data-semver="1.2.14" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-route.js"></script>
)中的路由模块完全相同来解决它,您所拥有的模块可能是更高版本。这应该有用。