Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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 ng视图不随路线显示(angularjs)_Javascript_Angularjs_Routes_Ng View - Fatal编程技术网

Javascript ng视图不随路线显示(angularjs)

Javascript ng视图不随路线显示(angularjs),javascript,angularjs,routes,ng-view,Javascript,Angularjs,Routes,Ng View,我正在做关于angularjs的教程。在使用route之前,一切正常。 我以前一直在研究这个问题,但它对我不起作用。 我正在做作者输入的代码,但它不起作用。 ng视图放入index.html <html ng-app="githubViewer"> <head> <title>Demo</title> <script type="text/javascript" src="js/angular.min.js"></

我正在做关于angularjs的教程。在使用route之前,一切正常。 我以前一直在研究这个问题,但它对我不起作用。
我正在做作者输入的代码,但它不起作用。 ng视图放入index.html

<html ng-app="githubViewer">
<head>
    <title>Demo</title>
    <script type="text/javascript" src="js/angular.min.js"></script>
    <script type="text/javascript" src="js/angular-route.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <script type="text/javascript" src="MainController.js"></script>
    <script type="text/javascript" src="github.js"></script>
</head>
<body>
    <h1>Github Viewer</h1>
    <div ng-view=""></div>
</body>
MainController.js

(function() {
var app = angular.module("githubViewer");
var MainController = function(
        $scope, $interval, $location) {
    var decrementCountdown = function() {
        $scope.countdown -= 1;
        if ($scope.countdown < 1) {
            $scope.search($scope.username);
        }
    };
    var countdownInterval = null;
    var startCountdown = function() {
        countdownInterval = $interval(decrementCountdown, 1000, 5, $scope.countdown);
    };
    $scope.search = function(username) {
        if (countdownInterval) {
            $interval.cancel(countdownInterval);
            $scope.countdown = null;
        }
    };
    $scope.username = "angular";
    $scope.countdown = 5;
    startCountdown();
};
app.controller("MainController", MainController);})();

您的代码中有一个错误:

var MainController = function($scope, $interval, , $location) {
                   // unnecessary comma here ----^
删除逗号(或插入缺少的参数),您的应用程序将开始工作


一般来说,我建议在编码过程中始终打开开发人员控制台。

在粘贴代码时,这是我的错误。在我的资料中,这是正确的。我想这是我使用的路线的问题。是的。在MainController.js中,如果我这样放置[]:var app=angular.module(“githubViewer”,[]);没有错误,但ng视图未显示。如果我像这样删除[](完全是作者类型):var app=angular.module(“githubViewer”);它的错误和链接:什么是
$templatereRequest
?您确定要显示所有的代码吗?只有一个文件github(我在帖子中更新了),让服务获取数据。但我认为这与问题无关。还有$templateRequest,我也不知道它是什么。你的代码看起来很好,然后和你的相比。
<div>
{{countdown}}
    {{username}}
    <form name="searchUser" ng-submit="search(username)">
        <input type="search" required placeholder="usẻname to ind" ng-model="username" />
        <input type="submit" value="Search" ng-click="search(username)">
    </form>
(function() {

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);})();
var MainController = function($scope, $interval, , $location) {
                   // unnecessary comma here ----^