daisy
daisy

Reputation: 23581

Changing location with $location

I'm trying to change the location to the edit page, when the user created a new document,

So I will need to change from, #/pages/fp_add to #/pages/fp_add?id=

But both of the following is not functioning,

$location.path ('/pages/fp_add?id=' + id);
$location.path ('#/pages/fp_add?id=' + id);

I guess angular take it as the same page, with or without the parameter?

Any ideas? It doesn't trigger reload

Attached route config,

app.config(function($routeProvider, $locationProvider) {
  $routeProvider.when('/pages/:name', {
    templateUrl: function(urlattr) {
      return 'templates/' + urlattr.name + '.html';
    },
    controller: function($scope, $routeParams, $controller) {
      $controller($routeParams.name, {
        $scope: $scope,
        $routeParams: $routeParams
      });
    }
  }).otherwise({
    redirectTo: '/pages/dashboard'
  });
});

Upvotes: 0

Views: 51

Answers (3)

daisy
daisy

Reputation: 23581

Looks like the right way is to simply execute

location.href = '#/pages/fp_add?id=' + id

If there's a angular way, let me know

Upvotes: 0

limekin
limekin

Reputation: 1944

You can use $route.updateParams({ id: id}) to reload the current path with new parameters, even if the url segments are the same. You need to have the $route service as your dependencies though.

Upvotes: 0

Ahmed Eid
Ahmed Eid

Reputation: 1183

Why don't you try $location.search function

$location.path('/pages/fp_add/').search({id: id});

UPDATE: I think you should use something like this

.when('/pages/:name/:id', {

so you can accept id as a parameter

Upvotes: 1

Related Questions