這是我的app.js單頁的應用程序,問題讓其他頁面的數據使用AngularJs
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider){
$routeProvider.when('/',{
templateUrl: 'views/home.html',
controller: 'homeCtrl'
}).when('/detail',{
templateUrl: 'views/details.html',
controller: 'detailCtrl'
}).otherwise({
redirectTo: '/home'
});
});
myApp.controller('homeCtrl',function($scope){
$scope.message ="Welcome to your Home Page"
});
myApp.controller('detailCtrl',function($scope){
$scope.message ="Name: Manish"
});
這是index.html頁面,
<html >
<head>
<meta charset="ISO-8859-1">
<title>Try It Out</title>
<script type="text/javascript" src="js/angular.js"></script>
<script type="text/javascript" src="js/angular-route.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body ng-app="myApp" ng-controller="homeCtrl" style="text-align: center;">
<span ><a href="/">{{message}}</a></span><br>
<a href="#/">Home</a>
<a href="#/detail">Details</a>
<br><br>
<div ng-view></div>
<h4>copyright 2017</h4>
</body>
</html>
這是我home.html的
<h3>Home</h3><br>
{{message}}
在details.html相同
<h3>Details</h3><br>
{{message}}
問題是當我在服務器上運行它首先在主頁上,但是當我點擊details..its不顯示Details.html的消息。 及主要問題是URL ...點擊詳細信息鏈接..
http://localhost:7675/AngularJSinglePage/#!/#%2Fdetail
如u可以看到「!/#%2F」這來自於between..don't來自哪裏,它應該知道像這樣
http://localhost:7675/AngularJSinglePage/#/detail
任何一個人都面臨同樣的問題?幫助我,我正在嘗試使用AngularJS學習SPA?
你有沒有嘗試過的'/'刪除''#?在你的'
Yup i did try removing "#" before "/" . then when i click on "Details" achor link ,then URL comes like this (http://localhost:7675/detail) but it should be like (http://localhost:7675/AngularJSinglePage/detaul) – Manish