AngularJS change route by ng-click using ui-router

2019-01-18 09:16发布

问题:

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?

回答1:

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