我嘗試學習AngularJS。目前我專注於ui-Routing。我的代碼非常簡單,但它可以工作,我不知道爲什麼。我的問題基本的UI路由示例,但發生錯誤
說明:
http://de.tinypic.com?ref=kd22ow.jpg
的瀏覽器顯示: 的 「Hello World UI路由!」 (index.html中的h1)
如果我嘗試輸入index.html/home。 它說:找不到錯誤文件!
這裏是我的代碼:
的index.html
<html>
<head>
<title>My Angular App!</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="Test" ng-controller="MainCtrl">
<h1>Hello World ui-Routing!</h1>
<div ui-view>
</div>
</body>
</html>
app.js:
angular.module('Test', ['ui-router'])
.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterprovider)
{
$stateProvider
.state('home', {
url: '/home',
templateUrl: '/home.html',
controller: 'MainCtrl'
});
.state('test', {
url: '/test',
templateUrl: '/test.html',
controller: 'TestCtrl'
});
$urlRouterProvider.otherwise('home');
}])
.controller('MainCtrl', ['$scope',
function($scope){
$scope.test = "Hello Jan!";
});
.controller('TestCtrl', ['$scope',
function($scope){
$scope.test = "Hello Redirect!";
});
的test.html:
<h2>Hello Test! </h2>
home.html的:
<h2>Hello Home! </h2>
我的問題在哪裏?
期待您的回答, 揚
如何管理靜態文件? – Unrealsolver 2014-10-02 12:15:07
所有文件都在同一個文件夾中。 – Peter 2014-10-02 18:37:20
也許,您必須安裝服務器。例如:npm install static-server; static-server – Unrealsolver 2014-10-03 14:05:45