angularjs - Angular UI Router states -


i have 2 states. 1 state table domains , second state information domain. table has filters (dropdown selects, dropdown checkboxes) can applied table data. can click domain table triggers second state (state1.domain).

my question when click away state1 state1.domain , click state1 how can preserve filtered data , not reinitialize controller? currently, when click state1 filters have been cleared , table data.

$stateprovider .state ('state1', {     url: '/state1',     views: {         "main@": {             controller: 'stateonectrl',             templateurl: 'folder/state1.tpl.html'         }     },     ncybreadcrumb: { label: 'state one' },     data: { pagetitle: 'state one', showtitle: false} }) .state('state1.domain', {     url: '/:domain',     views: {         "main@": {             controller: 'stateonedomainctrl',             templateurl: 'folder/state1-domain.tpl.html'         }     },     ncybreadcrumb: { label: '{{domain}}' },     data: { pagetitle: 'state 1 domain', showtitle: false } }) 

using services

you can store theses values in service. on controller initialization set controllers var stored var in service.

may best solution.

using session storage

in opinion 1 of way go using session storage store filters within navigation flow application.

in controller init filters vars :

$scope.filtername = sessionstorage.filtername 

on each filter change save sessionstorage value

//in html on filter ng-change="onfilternamechange()"  //in js $scope.onfilternamechange = function(){     sessionstorage.filtername = $scope.filtername } 

and that's pretty all.

if want able "clean" filters manage optional url param (like ?resetfilters=true) clean filters.

using query params

you (if there not filters) explicitly sets filters in url

.state ('state1', {     url: '/state1?filter1&filter2&filter3',     views: {         "main@": {             controller: 'stateonectrl',             templateurl: 'folder/state1.tpl.html'         }     },     ncybreadcrumb: { label: 'state one' },     data: { pagetitle: 'state one', showtitle: false} }) 

but may stuck can't give object url (whereas can stringify 1 sessionstorage.

hope helped.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -