2

I have ASP.NET application where we use AngularJS. The issue is when we click "edit" the new view is openinig in the same window (tab). How to open it in new window (tab)? Here's the code:

List.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);
};
tesicg
  • 3,971
  • 16
  • 62
  • 121
  • Did you try `window.open("/edit/" + id);` – Nilesh Feb 18 '15 at 07:05
  • Possible duplicate of http://stackoverflow.com/questions/20099784/open-links-in-new-window-using-angularjs – morsor Feb 18 '15 at 07:08
  • @Nilesh: It doesn't work because there is some path got by $location.path. – tesicg Feb 18 '15 at 07:15
  • If you have to show a different HTML file then use `window.open`. What is `/edit/' + id; is it a URL to some different html? – Nilesh Feb 18 '15 at 07:44
  • The first url is: http://example.com/admin/Admin_Users.aspx#/list From that url we click "edit" and should go to: http://example.com/admin/Admin_Users.aspx#/edit/id – tesicg Feb 18 '15 at 07:51
  • 1
    `$location.path` just returns the path of current page. instead you need the url which actually points to a different location, so when you call window s open function it should have `window.open('example.com/admin/Admin_Users.aspx#/edit/id')`. If you want to build the url dynamically use `$location.host()`, `$location.protocol()` etc to build a url and then append `/edit/id` at the end. – Nilesh Feb 18 '15 at 08:18
  • @Nilesh: I already did it in the meantime. If you want, please, write your last comment as an answer and I'll mark it as accepted answer. – tesicg Feb 18 '15 at 08:54

2 Answers2

0

this work for me

$window.open(url);
0

$location.path just returns the path of current page. instead you need the url which actually points to a different location, so when you call window s open function it should have window.open('example.com/admin/Admin_Users.aspx#/edit/id'). If you want to build the url dynamically use $location.host(), $location.protocol() etc to build a url and then append /edit/id at the end

Nilesh
  • 2,583
  • 5
  • 21
  • 34