用于加载所有文件的HTML代码 Javascript文件UserController.js和RepoController.js没有加载,因此没有显示在开发人员工具源选项卡中。当我在网络选项卡中按F5时,文件已加载但操作没有完成。
<!DOCTYPE html>
<html>
<head>
<title>Angular World</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular-route.js"></script>
<script src="../scripts/jquery-3.3.1.js"></script>
<script src="../scripts/bootstrap.js"></script>
<link href="../Content/bootstrap.css" rel="stylesheet" />
<script src="../Javascript/Route/Route.js"></script>
<script src="../Javascript/Service/Service.js"></script>
<script src="../Javascript/Controller/MainController.js"></script>
<script src="../Javascript/Controller/UserController.js"></script>
<script src="../Javascript/Controller/RepoController.js"></script>
<meta charset="utf-8" />
</head>
<body ng-app="app">
<h1>Github User/Repo Search</h1>
<div ng-view></div>
</body>
Javascript控制器功能:
(function () {
var app = angular.module('app');
var UserController = function ($scope, $routeParams, $location, userRepoService) {
$scope.userHeader = 'User Page';
$scope.header1 = 'Index #';
$scope.header2 = 'ID';
$scope.header3 = 'Name';
$scope.header4 = 'Size';
$scope.header5 = 'Stargazers Count';
$scope.header6 = 'Watchers';
let username = $routeParams.username;
let onReposComplete = function (data) {
$scope.repos = data;
};
let onUserComplete = function (data) {
$scope.user = data;
userRepoService.getRepos($scope.user).then(onReposComplete);
};
let onError = function () {
$scope.error = "Oops could not load user data";
};
userRepoService.getUser(username).then(onUserComplete , onerror);
};
app.controller('UserController', UserController);
}());
服务功能:
(function() {
var app = angular.module('app');
let userRepoService = function($http) {
let getUser = function(username) {
return $http.get('api.github.com/users/'; + username).then(function(response) {
return response.data;
})
};
let getRepos = function(user) {
return $http.get(user.repos_url).then(function(response) {
return response.data;
})
}
};
app.factory('userRepoService', userRepoService);
}());
答案 0 :(得分:0)
在我看来,你在MainController.js中有一个javascript错误,导致无法继续插入下一个代码。