JavaScript文件未加载



html代码加载所有文件JavaScript文件usercontroller.js和repocontroller.js尚未加载,因此未在"开发人员工具源"选项卡中显示。当我按加载网络选项卡文件中的F5时,请执行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);
}());

在我看来,您在maincontroller.js中有一个JavaScript错误,可防止继续解释下一个代码。

相关内容

  • 没有找到相关文章

最新更新