Search code examples
angularjsdevextreme

How I can save my data when location changed in AngularJs app?


I have a simple AngularJs application, at the HomePage.html I have a dx-datagrid with all data, to onSelectionChanged method I added the next code:

onSelectionChanged: function (e) {
        $scope.itemIdFromShowButton = e.selectedRowsData[0].id;
        $scope.cardSelectedArray = e.selectedRowsData[0];
        $scope.allRecordsOfCard= businessLogicOfMyApp.getVardsRecordsByCardId($scope.itemIdFromShowButton, $scope.recordsArray);
        $scope.localArray = $scope.chaptersArray.concat($scope.jdskla);
        console.log($scope.localArray);
    },

here i get all Records of card, and concat it with secondary array, it works: enter image description here

but, after my location is changet - array is empty: enter image description here

I want use is array like a dataSource in my dx-treeview at my CardDetail.html page.

myApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
    templateUrl: "Partials/HomePartial.html",
    controller: "defaultController"
})
.when('/createnewcard', {
    templateUrl: "Partials/CreateNewCard.html",
    controller: "defaultController"
})
.when('/carddetail/:cardId', {
    templateUrl: "Partials/CardDetails.html",
    controller: "defaultController"
})
.when('/createnewrecord/:cardId', {
    templateUrl: "Partials/CreateNewRecordToCard.html",
    controller: "defaultController"
})
  ;

$routeProvider.otherwise({ redirectTo: '/' });
}]);

may be somebody know how i can save my data ? Thanks for your answers !

P.S. i initialized $scope.localArray = []; at header of my code.


Solution

  • use $localStorage to save your array when is getting populated and if the state changes check for value in the local storage. If there is value in the local storage use that value for the array value