【问题标题】:AngularJS change route by ng-click using ui-routerAngularJS 使用 ui-router 通过 ng-click 更改路由
【发布时间】:2013-10-14 13:42:55
【问题描述】:

如何使用 ng-click 而不是应用 ui-sref 的链接来更改 route.state。

我试过了:

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

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

但它不起作用。有什么想法吗?

【问题讨论】:

标签: angularjs angular-ui angular-ui-router


【解决方案1】:

查看 ui-router 文档 wiki。

最好的解决方案是使用$state.go()。例如,$state.go('recorder.options')

这是文档中特定功能的链接: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options

【讨论】:

  • tyvm,我之前试过。但忘记注入 $state .. 所以它没有用。现在一切都很好.. 非常感谢 :)
  • $state 注入所有视图的一种方法是使用angular.module('myApp').run(['$rootScope', '$state', function($rootScope, $state) { $rootScope.$state = $state; }]);
猜你喜欢
  • 2014-03-13
  • 1970-01-01
  • 2014-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 2016-05-25
相关资源
最近更新 更多