Ui-router prevents transition to reload parent state
I have a basic search results page. This is my ui-router config:
$stateProvider
.state('search', {
url: '/search',
templateUrl: 'app/templates/search.html',
controller: 'searchController'
})
.state('search.results', {
url: '/results/:searchParameters',
templateUrl: 'app/templates/results.html',
controller: 'resultController'
});
This is how I send parameters from search to search.results, which actually does the GET
$scope.search = function () {
if (!$state.is('search.results')) {
$state.go('search.results', { searchParameters: $scope.searchParameters });
}
else {
$state.transitionTo('search.results', { searchParameters: $scope.searchParameters }, { reload: true, inherit: true, notify: true });
}
};
and this is my search for .html
<div class="row">
<form name="parameters" role="form" class="form-search" novalidate>
<input type="text" class="form-control uppercase" placeholder="Codice manifestazione"
ng-enter="search()" ng-model="searchParameters.maniCode" />
<input type="number" class="form-control" placeholder="Anno"
ng-enter="search()" ng-model="searchParameters.year" maxlength="4" required/>
<br />
<label>Stato manifestazioni:</label>
<select ng-enter="search()" ng-model="searchParameters.open" ng-init="searchParameters.open = true">
<option value="true">Aperte</option>
<option value="false">Chiuse</option>
</select>
<br />
<br />
<input type="button" value="Cerca" class="btn btn-default"
ng-click="search()"
ng-disabled="(parameters.$invalid || parameters.$pristine) || (clicked && !loaded)"/>
<input type="button" value="Esporta in Excel" class="btn btn-default"
ng-click="excelMain()"
ng-disabled="(parameters.$invalid || parameters.$pristine) || (clicked && !loaded)" />
<br />
<br />
<ul class="noStyleUl">
<li ng-show="searchParameters.year.length < 4">Inserisci un anno per abilitare la ricerca</li>
</ul>
</form>
<div ui-view>
</div>
</div>
Unfortunately, $ state.transitionTo will not only reload search.results (good), but reload search (bad!), Thus clearing my form.
What I have done right now is to send an event from the ResultsController to the SearchController to restore the scope and thus "fill in" the form. I would like to know if there is a better solution.
Thank.
+3
source to share