【问题标题】:How to open new window (tab) in AngularJS?如何在 AngularJS 中打开新窗口(选项卡)?
【发布时间】: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

标签: asp.net angularjs


【解决方案1】:

$location.path 只是返回当前页面的路径。相反,您需要实际指向不同位置的 url,因此当您调用 window 的 open 函数时,它应该具有 window.open('example.com/admin/Admin_Users.aspx#/edit/id')。如果要动态构建 url,请使用 $location.host()、$location.protocol() 等来构建 url,然后在末尾附加 /edit/id

【讨论】:

    【解决方案2】:

    这对我有用

    $window.open(url);
    

    【讨论】:

    • 在我的情况下 url 应该是什么?
    猜你喜欢
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多