AngularJS:ngRoute,否则无效

 晴华姐姐_286 发布于 2023-01-09 11:03

我有一个非常奇怪的错误,我设置了我的路线和我的控制器.现在我只有一个没有错误的空白页面?

index.html的;



    
        Rekentalent.nl: Ben jij een talent in Rekenen?
        
        
        
        
        
        
        
        
        
        
    

    


>

Controller.js:

/**
*  RekenTalent
*
* Copyright 2014 - Rekentalent.nl
*/
var RekenTalent = angular.module('RekenTalentControllers', []);

RekenTalent.controller('rekenCtrl', ['$scope', function($scope){

}]);

Router.js:

var RekenTalent = angular.module('RekenTalent', [
    'ngRoute', 'RekenTalentControllers'
]);

RekenTalent.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
    when('/index', {
        templateUrl: '/templates/index.html',
        controller: 'rekenCtrl'
    }).
    otherwise({
        redirect: '/index'
    });
}]);

而/templates/index.html只是说'嗨'.有谁知道为什么我得到一个空白页面?它应该将我重定向到/index.html,而/index.html应该使用/templates/index.html作为模板.问题和解决方案是什么?

更新:

当我去/索引它工作,所以否则param不工作,为什么不呢?

1 个回答
  • 改变redirectredirectTo

    最好使用home.template来避免所有这类问题,我的意思是考虑:

    你有一个index.html包含整个包含的脚本,如angular,jquery,...,并且在body标签中有ng-view,好吗?

    现在,如果你有任何模板,如欢迎或索引的任何模板,写一个模板home.html,好吗?像这样:

    index.html:

    <body ng-app="yourapp">
       <div ng-view>
       </div>
    </body>
    

    Home.html中

      <div>
         Welcome, user. This is index.
      </div>  
    

    您的应用配置:

    yourapp.config(function($routeProvider) {
       $routeProvider
          .when('/', {
             templateUrl: 'partials/home.html',
             controller: 'homeCtrl'
          })
          .otherwise({redirectTo:'/'});
    }
    

    将所有模板放在partials文件夹中是一个很好的做法,其中father文件夹包含index.html

      root 
         yourAppFolder
           1-Assets
              Css
              Js
    
           2-Partials
              home.html
              login.html
    
           3-index.html
    

    2023-01-09 11:06 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有