使用 AngularJs 在单页应用程序中获取其他页面的数据问题
issue getting data of other page in a single page application using AngularJs
这是我的 app.js,
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}}
问题是当我 运行 它在服务器上时,当我单击详细信息时它会转到 first.but 的主页..它没有显示 Details.html 的消息。
主要问题是 URL...单击详细信息 link..
http://localhost:7675/AngularJSinglePage/#!/#%2Fdetail
你可以注意到“!/#%2F”介于两者之间..不知道从哪里来,它应该是这样的
http://localhost:7675/AngularJSinglePage/#/detail
有人遇到过同样的问题吗?帮帮我,我正在尝试使用 AngularJS?
学习 SPA
已回答@:)
此外,您的 app.js 中没有 spaController,它在您的
中被引用
这是我的 app.js,
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}}
问题是当我 运行 它在服务器上时,当我单击详细信息时它会转到 first.but 的主页..它没有显示 Details.html 的消息。 主要问题是 URL...单击详细信息 link..
http://localhost:7675/AngularJSinglePage/#!/#%2Fdetail
你可以注意到“!/#%2F”介于两者之间..不知道从哪里来,它应该是这样的
http://localhost:7675/AngularJSinglePage/#/detail
有人遇到过同样的问题吗?帮帮我,我正在尝试使用 AngularJS?
学习 SPA已回答@
此外,您的 app.js 中没有 spaController,它在您的
中被引用