angularjs中的$ routeProvider无法正常工作

时间:2017-10-28 02:52:06

标签: angularjs

this is my test.js file
angular.module("testApp",['ngRoute'])
.config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider){

    $routeProvider
    .when("/test",{
        templateUrl: 'test.html',
        controller: 'testCtrl'
    })
   .otherwise({
        redirectTo : "/test" 
    });

    $locationProvider.html5Mode(true);
    
}]).controller("testCtrl",function(){
    this.message = "hello";
    console.log("in controller");
})
this is index.html

<!DOCTYPE html>
<html ng-app="testApp">
<head>

	<script src="angular.js"></script>
	<script src="angular-route.js"></script>
	<script src="test.js"></script>
	<base href="/">

</head>

<body>
	<div ng-view></div>
</body>
</html>


this is test.html file

<div ng-controller="testCtrl as tCtrl">
  <h1>{{tCtrl.message}}</h1>
</div>

当我点击http://127.0.0.1:8080/时,它被重定向http://127.0.0.1:8080/test并且它正在加载所有资源,即controller和angualar.js。 但当我点击http://127.0.0.1:8080/test时,它不会加载任何给出{{tCtrl.message}}

的内容

如何解决此问题。

0 个答案:

没有答案