1

I am redirecting to edit page after clicking on edit button.

<button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit"  ng-click="editData(n.id.userId)"><span class="glyphicon glyphicon-pencil"></span></button>

On click on this button following code is working.

$scope.editData = function (data, $window) {
     console.log(data);
     window.location = 'update-data?id=' + data;
}

Now I am redirected to www/xxx/update-data?id=1 url. From there I want to fetch user data for id=1 and want to show at page. How to achieve this?

xrcwrn
  • 5,339
  • 17
  • 68
  • 129

2 Answers2

0

You can fetch the Url using $window and do one of the following based on your requirement

var url = "www/xxx/update-data?id=1";
var id = url.substring(url.indexOf('=')+1);
console.log(id);
var url = "www/xxx/update-data?id=1";
var id = url.substring(url.indexOf('?')+1);
console.log(id);

But the best option (angular way of doing things) will be to do routing and use $routeParams or $stateparams based on your router.

Relevant Links:

  1. Configure Routes and Views using $routeProvider
  2. Documentation ngRoute
  3. UI-Router for AngularJS (1.x)
  4. Get Current URL
Vivz
  • 6,625
  • 2
  • 17
  • 33
  • I an doing as above is correct or i have to use ng route – xrcwrn Sep 13 '17 at 09:38
  • If you don't have that many routing, I guess above method will be fine. But if your application so many pages, then it is better to use routing. – Vivz Sep 13 '17 at 09:39
0

You can parse the url and get id and write code to get the data for the corresponding id inside ngOninit ()

Vinujan.S
  • 1,199
  • 14
  • 27