我正在使用 Angular 开发一个单页移动网络应用程序。
第一次我将加载partial-For-routes-1.html
,然后从我想要转到partial-For-routes-2.html
并partial-For-routes-3.html
使用链接,我如何提供指向第 2 页和第 3 页的链接,是href
像下面使用的那样更好还是更好地使用ng-href
?
在普通的桌面网络应用程序中,我们可以只使用要加载的页面的相对路径href
属性。我不知道如何在带有部分的 Angular js 框架中做到这一点。请帮助我。提前致谢。
请纠正我,我使用正确的语法链接到部分。
Index.html
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My HTML File</title>
<title>Google Phone Gallery</title>
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="lib/angular/angular.js"></script>
<script src="js/controllers.js"></script>
<script src="js/routes.js"></script>
</head>
<body ng-controller="appCtrl">
<div class="" ng-view></div>
</body>
</html>
app.js
angular.module('myApp', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/',
{
templateUrl: 'partials/partial-For-routes-1.html',
controller: appCtrl
}).
when('/page-2',
{
templateUrl: 'partials/partial-For-routes-2.html',
controller: appCtrl
}).
when('/page-3',
{
templateUrl: 'partials/partial-For-routes-3.html',
controller: appCtrl
}).
otherwise({redirectTo:("/")})
}]);
partial-For-routes-1.html
<p>Total number of phones: 1</p>
<p>Total number of phones: 1</p>
<p>Total number of phones: 1</p>
<p>Total number of phones: 1</p>
<p>Total number of phones: 1</p>
<p>Total number of phones: 1</p>
<p><a href="#/page-2" class="">Go to Page 2</a></p>
<p><a href="#/page-3" class="">Go to Page 3</a></p>
partial-For-routes-2.html
<p>Total number of phones: 2</p>
<p>Total number of phones: 2</p>
<p>Total number of phones: 2</p>
<p>Total number of phones: 2</p>
<p>Total number of phones: 2</p>
<p>Total number of phones: 2</p>
<p><a href="#/page-1" class="">Go to Page 1</a></p>
<p><a href="#/page-3" class="">Go to Page 3</a></p>
partial-For-routes-3.html
<p>Total number of phones: 3</p>
<p>Total number of phones: 3</p>
<p>Total number of phones: 3</p>
<p>Total number of phones: 3</p>
<p>Total number of phones: 3</p>
<p>Total number of phones: 3</p>
<p><a href="#/page-1" class="">Go to Page 1</a></p>
<p><a href="#/page-2" class="">Go to Page 2</a></p>