AngularJS change route by ng-click using ui-router

marcel picture marcel · Oct 14, 2013 · Viewed 39.7k times · Source

How can I change the route.state using ng-click instead of a link applying ui-sref.

I've tried this:

<button ng-click="selectDir(file.fullPath)">set</button>

with

$scope.selectDir = function(location) {
    options.storageLocation = location;
    $route.current = 'recorder.options';
}

But it doesn't work. Any ideas?

Answer

bendalton picture bendalton · Oct 14, 2013

Check out the ui-router documentation wiki.

The best solution is to use $state.go(). e.g., $state.go('recorder.options')

Here's the link to the specific function in the documentation: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options