使用按钮单击重定向到另一个页面

Redirecting to another page using a button click

我想在单击按钮时重定向到另一个网页。请找到以下代码

js

app.controller('myCtrl', ['$scope', '$location', function($scope, $location) {

$scope.redirect = function()
{
console.log($location.url());

};

}

我可以使用下面的 $location.url() 获得当前 url

http://IP:Port/?myId=this-is-my-test-page

我想做的是当我点击一个按钮时重定向到下面的页面

http://IP:Port/?myId=this-is-my-test-page2

我想编辑控制器内现有的 url 而无需对整个 url 进行硬编码,因为 IP 和端口可以更改。我怎样才能做到这一点?

虽然我用过$location.path("http://IP:Port/?myId=this-is-my-test-page2"); 它的作用是附加到当前 url 如下

http://IP:Port/?myId=this-is-my-test-page2#http://IP:Port/?myId=this-is-my-test-page2

如何重定向到所需页面?

我有一个不太相似的问题,我必须将变量转换为字符串,然后修改字符串。然后转换回正确的数据类型。

Angular有自己的路由。 # 右边的所有内容都是 Angular 路由(客户端路由)。 #号左边的一切都是你的MVC/WebApi路由(服务器端路由)。这是单页应用的本质。

如果您想更改服务器端路由,您需要在服务器端进行重定向,因此向服务器请求更改 url。如果您想更改客户端 (Angular) 路由,您需要在 angular 代码中使用“$location.path('')”。请注意,您不能更改客户端# 号左侧的任何内容。

您正在尝试更改 url 的服务器端部分,因此您需要向服务器发出请求以更改 url。

有关两者的更多信息,请参阅 this question

我尝试使用 $window.location 并且成功了。其他方法均无效。

app.controller('myCtrl', ['$scope', '$window', function($scope, $window) {

$scope.redirect = function()
{
$window.location = "http://IP:Port/......";

};

}