我有一个非常奇怪的错误,我设置了我的路线和我的控制器.现在我只有一个没有错误的空白页面?
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不工作,为什么不呢?
改变redirect
以redirectTo
最好使用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