Unable to redirect to new page using angular.js's $location or $window

时间:2017-04-06 17:11:22

标签: javascript html angularjs html5 redirect

I am developing my first app using angular.js (v 1.6.3) and I am stuck on a very basic problem. I have created a list page for "User Group", and on this list I have a Edit button. On click event of this edit button, I want to redirect the record id to edit page. Below is code for my button:

<button data-ng-click="editUserGroup(userGroup.id)">&#9998;Edit</button>

Below is the code for editUserGroup

$scope.editUserGroup = function(userGroupId) {
    //$location.path("/userGroup.html").search({c:'edit', id:userGroupId});
    //$scope.$apply();
    $window.location.href = './userGroup.html#/?c=edit&id='+userGroupId;
}

In short, I want to redirect to edit page and also need to pass 2 parameters, ?c=edit&id=<actual id here>

As you can see in my above code, $location.path() not working as it is not reloading new page, rather changing the URL only like <Some URL>/listUserGroup.html#!/userGroup.html?c=edit&id=1. If I use $window.location.href, I can redirect to new page but #/ is getting HTML encoded like below <Some URL>/userGroup.html#!#%2F%3Fc=edit&id=1

How should I redirect to new page and pass both the parameters using angular.js?

1 个答案:

答案 0 :(得分:0)

因此,从评论中提示,我使用var AllSelectedData = []; table.rows().every(function () { var d = this.data(); AllSelectedData.push(d); }); $("#dtlist").val(JSON.stringify(AllSelectedData)); 将页面重定向到下一页,并使用window.location存储我要发送到下一页的数据。