Javascript 使用angularJs重定向到其他项目
我的URL类似于: 在这个页面中,我想点击一个按钮,将我重定向到另一个用主干JS制作的项目的其他页面 我尝试使用href-和ng hrefJavascript 使用angularJs重定向到其他项目,javascript,angularjs,backbone.js,Javascript,Angularjs,Backbone.js,我的URL类似于: 在这个页面中,我想点击一个按钮,将我重定向到另一个用主干JS制作的项目的其他页面 我尝试使用href-和ng href添加所需的URIhttp://localhost:3000/admin#exemption:但它总是将我重定向到http://localhost:3000/family/#/admin#exemption angular.module('app', ['ng', 'ngRoute', 'ui.bootstrap', 'angularMoment', 'c
添加所需的URIhttp://localhost:3000/admin#exemption
:但它总是将我重定向到http://localhost:3000/family/#/admin#exemption
angular.module('app', ['ng', 'ngRoute', 'ui.bootstrap', 'angularMoment', 'chart.js'])
.config(fac['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/index', {
templateUrl: '/family/index',
controller: 'IndexCtrl'
})
.when('/family/exemption', {
templateUrl: 'exemption-search-view'
})
当我给出所需页面的模板时,我获得了html视图,但URI:
http://localhost:3000/family/#/admin#exemption
如果您的其他项目不是angular应用程序的一部分,您应该重定向到其他URL
angular.module('app', ['ng', 'ngRoute', 'ui.bootstrap', 'angularMoment', 'chart.js'])
.config(fac['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/index', {
templateUrl: '/family/index',
controller: 'IndexCtrl'
})
.when('/family/exemption', {
templateUrl: 'exemption-search-view'
})
只需使用
ng href是在URL中的哈希之后附加您传递的URL的,如果您的其他项目不是angular应用程序的一部分,您应该重定向到另一个URL 只需使用
ng href是在URL中的散列之后附加您要传递的URL的,我不确定是否理解这个问题,但是如果您想避免角度路由拦截,您应该添加锚定目标=“\u self”
我不确定是否理解这个问题,但如果您想避免角度路由拦截,则应添加锚定目标=“\u self”
不要使用href(或任何变体)重定向,尝试使用控制器中的函数将您重定向到新url。试着这样做:
// in your controller
angular.module('app', ['ngRoute'])
.controller('redirectCtrl', function($window, $location){
var vm = this;
vm.wizard = {
anotherurl: "http://example.com",
redirect: fnRedirect
}
return vm.wizard;
function fnRedirect(link){
//this way is useful if you try to redirect to an external URL
$window.location = link;
//this way is useful if you try to redirect to another route inside the same angular project
$location.path(link);
}
});
…在你的html中
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body data-ng-controller="redirectCtrl as rc">
<input type="text" data-ng-model="rc.anotherurl" />
<a href="" data-ng-click="rc.redirect(rc.anotherurl)">Redirect me</a>
</body>
</html>
不要使用href(或任何变体)重定向,尝试使用控制器中的函数将您重定向到新url。试着这样做:
// in your controller
angular.module('app', ['ngRoute'])
.controller('redirectCtrl', function($window, $location){
var vm = this;
vm.wizard = {
anotherurl: "http://example.com",
redirect: fnRedirect
}
return vm.wizard;
function fnRedirect(link){
//this way is useful if you try to redirect to an external URL
$window.location = link;
//this way is useful if you try to redirect to another route inside the same angular project
$location.path(link);
}
});
…在你的html中
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body data-ng-controller="redirectCtrl as rc">
<input type="text" data-ng-model="rc.anotherurl" />
<a href="" data-ng-click="rc.redirect(rc.anotherurl)">Redirect me</a>
</body>
</html>
Angular中的问题是,它将您重定向到他的URL中的同一个基,因此如果您想更改基(在我的情况下是/family/#/),就好像您要从项目中转到外部URL,所以我刚刚在控制器中添加了:
$window.location.href ='http://localhost:3000/admin#exemption' ;
我的“$routeProvider”中不需要任何更新。Angular中的问题是,它会将您重定向到他的URL中的同一个基,因此如果您想更改基(在我的情况下是/family/#/),就好像您要从项目中转到外部URL,所以我刚刚在控制器中添加了:
$window.location.href ='http://localhost:3000/admin#exemption' ;
我的“$routeProvider”不需要任何更新。如果你想删除链接中的标签,你可以点击这个链接:如果你想删除链接中的标签,你可以点击这个链接:添加,在文档中:在“HTML链接重写”下。添加,在文档中:在“HTML链接重写”下。为什么要重新创建
href
的操作?您不需要使用href=“指向其他应用程序的路径”
,而需要一个具有专用方法的控制器,并通过ng单击来处理链接。
?!我不同意你的看法。你为什么要重新创建href
的操作?您不需要使用href=“指向其他应用程序的路径”
,而需要一个具有专用方法的控制器,并通过ng单击来处理链接。
?!我不同意你的看法。