splash27 splash27 - 6 months ago 12
AngularJS Question

How to route to same location to restart view and controller binding (angularjs)?

Actually, I want something like this

location.path(location.url());
but angular by default doesn't allow this. Is there a way to override it?

I need this to renew view and controller binding?

Why?

So, I have in my model statements like this:

$scope.instance =
{
City: gettextCatalog.getString(cityName),
Country: gettextCatalog.getString(countryName),
}


So, if I change a language, the
$scope.instance
will not be recalculated. I think, that rebinding on reroute is more easy way than inserting every 'instance' in function, that will be called after language changed.

Answer

If you are using ngRoute

$route.reload()

$route is used for deep-linking URLs to controllers and views (HTML partials). It watches $location.url() and tries to map the path to an existing route definition.

reload(); Causes $route service to reload the current route even if $location hasn't changed. As a result of that, ngView creates new scope and reinstantiates the controller.

If you are using ui.router

$state.go($state.$current, null, { reload: true });