我创建了一个html文件并制作了一个锚标记。
<a href="http://localhost:8888/#/product" target="_blank">product</a>
我想在http://localhost:8888/#/product
中打开角度应用,但会重新加载到http://localhost:8888/#/
。
我可以在角度应用中修复哪些内容,以便在新标签中打开这种网址?谢谢。
答案 0 :(得分:0)
使用ui-router,您可以使用ui-sref =“stateName”来更改视图。
以下是一个例子:
<a ui-sref="routeHere" target="_blank">A Link</a>
注意:您只能打开一个新标签页:
目标= “_空白”
仅当您使用锚标记和ui-sref。
时此处有更多信息:https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref
答案 1 :(得分:0)
使用AngularJS Routing完成它。
如果您想导航到应用程序中的不同页面,但您还希望应用程序成为SPA(单页应用程序),而不重新加载页面,则可以使用ngRoute模块。
ngRoute模块将您的应用程序路由到不同的页面,而无需重新加载整个应用程序。
实施例: 导航到&#34; red.htm&#34;,&#34; green.htm&#34;和&#34; blue.htm&#34;:
<body ng-app="myApp">
<p><a href="#/">Main</a></p>
<a href="#red">Red</a>
<a href="#green">Green</a>
<a href="#blue">Blue</a>
<div ng-view></div>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/red", {
templateUrl : "red.htm"
})
.when("/green", {
templateUrl : "green.htm"
})
.when("/blue", {
templateUrl : "blue.htm"
});
});
</script>
要使您的应用程序为路由做好准备,您必须包含AngularJS路由模块:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
然后,您必须在应用程序模块中添加ngRoute作为依赖项:
var app = angular.module("myApp", ["ngRoute"]);