【发布时间】:2015-04-19 02:46:46
【问题描述】:
我有使用 AngularJS 的 ASP.NET 应用程序。问题是当我们单击“编辑”时,新视图会在同一窗口(选项卡)中打开。如何在新窗口(标签)中打开它?代码如下:
列表.html:
<td><a ng-click="editUser(u.ID)">edit</a></td>
AngularJS:
AdminUsersApp.controller("ListController", function ($scope, $location, $http, ErrorUI, Users, Cashdesks) {
...
$scope.editUser = function (id) {
$location.path("/edit/" + id);
};
【问题讨论】:
-
你试过
window.open("/edit/" + id); -
@Nilesh:它不起作用,因为 $location.path 有一些路径。
-
如果您必须显示不同的 HTML 文件,请使用
window.open。什么是`/edit/' + id;它是指向不同 html 的 URL 吗? -
$location.path只是返回当前页面的路径。相反,您需要实际指向不同位置的 url,因此当您调用 window 的 open 函数时,它应该具有window.open('example.com/admin/Admin_Users.aspx#/edit/id')。如果要动态构建 url,请使用$location.host()、$location.protocol()等构建 url,然后在末尾附加/edit/id。