1

Save Check Box State with AngularJs ... For back button from another page.

I have a complex search page that is generated via AngularJS like so

<input type="checkbox" class="checkall" id="all_types"><strong><?=lang('select_all')?></strong>  
<div class="span12" ng-controller="typesCtrl"> 
<label class="checkbox inline" data-ng-repeat="record in records">
  <input type="checkbox" class="small_checkbox" value="{{ record.type_id }}" name="auto_type[]"> {{ record.en_type_name }} ({{ record.type_count }})

After search selection is complete I check what is selected and send it to a search url

/search?auto_type=1,4,5,7

The problem is when I click back button ... the state of checkboxes and select is not saved. What is the most elegant way to save checkbox state in this scenario.

xdotcommer
  • 48
  • 9
  • Store your state in a service or in a parent scope: http://stackoverflow.com/a/12960281/215945 – Mark Rajcok Mar 27 '13 at 00:26
  • Are you reloading the whole page when you send the data to a search url? – Sharondio Mar 27 '13 at 02:34
  • I am not reloading page I am just sending to another url via javascript window.location – xdotcommer Mar 30 '13 at 04:58
  • i have a similar problem. i open a pdf doc when a link is clicked, but when the user presses the back button, the whole angular app is restarted and all variables are cleared, which isnt desired in my case. im thinking of persisting everything in local storage. but this seems like a huge thing just to handle a back button – Anton May 05 '13 at 10:13
  • I am still looking for a solution with no luck at the moment. – xdotcommer May 05 '13 at 10:51

0 Answers0