【发布时间】:2019-09-15 18:18:06
【问题描述】:
我想在单击按钮时重定向到另一个网页。请找到以下代码
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");
它的作用是按如下方式附加到当前网址
http://IP:Port/?myId=this-is-my-test-page2#http://IP:Port/?myId=this-is-my-test-page2
如何重定向到所需的页面?
【问题讨论】:
-
你可能想参考Angular的documentation。我认为你应该定义routes。
-
我可以看到路线吗?
-
我还没有创建任何路线。不使用路线我不能这样做吗?
标签: html angularjs url-redirection