多页表单,后退按钮改变状态

时间:2015-01-15 14:28:57

标签: angularjs angular-ui-router

我有多页内容,内置了后退按钮。我想在chapterID达到0时更改状态。

$ state.go执行但随后重定向回gn.newChapter状态

HTML:

<a ui-sref="gn.newChapter({chapterID: id})" class="btn btn-primary"    ng-click="goBack()">Go Back</a>

控制器:

$scope.goBack = function() {
  if (newChapterService.getChapterState() === 0) {
    $state.go('gn.createGNForm');
  }
  else {
    $scope.id = newChapterService.goBackChapter();  
  }
};

1 个答案:

答案 0 :(得分:1)

<a class="btn btn-primary"    ng-click="goBack()">Go Back</a>



$scope.goBack = function() {
  if (newChapterService.getChapterState() === 0) {
    $state.go('gn.createGNForm');
  }
  else {
    $scope.id = newChapterService.goBackChapter();  
    $state.go('gn.newChapter({chapterID: $scope.id})'); // I don't know your predefined paths. so just suggesting this as an answer. This line might be different according to your need.
  }
};