Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Prevent the wiping of an Array after routing Angular.js

ou can try something similar

// Untested code

app.factory("chartService", function() {
    var chartData;

    function saveData(data) {
      chartData = data;          
    }

    function getData() {
      return chartData;
    }

    return {
      saveData: saveData,
      getData: getData
    };
});

app.controller("chartCtrl", function($rootScope, $scope, $interval, chartService) {
    var data = chartService.getData();       
    if (data) {
      // Navigating back
      $scope.data = data;
    } else {
       // First visit of the session
       $scope.data = [[],[],[]];
    }
    
     // interval code ...

    $scope.$on('$destroy', function() {
          chartService.saveData($scope.data);
          $interval.cancel(stopChart);
    });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: angularjs How do I show all indicators for carousel in an ng-repeat 
Javascript :: AngularJS stuck in module 
Javascript :: object Promise showing instead of data pulled from API call 
Javascript :: Chrome DevTools - why does variable display in Watch but not under Scope 
Javascript :: when selecting second dropdown ng-model object return null 
Javascript :: HTTP Get with looping password validation not working 
Javascript :: React Native Root Element, deciding on async call 
Javascript :: When doing a booking system, where would it be better to do? Back end or front end 
Javascript :: .push( ) is not updating the variable 
Javascript :: Save multiple radios checked on LocalStorage 
Javascript :: upsert typeorm 
Javascript :: react open popup to upload image file 
Javascript :: Node.js with Express: Importing client-side javascript using script tags in Jade views 
Javascript :: promsie js 
Javascript :: No enum constant datepicker react native 
Javascript :: javascript scrolltoview vue 
Javascript :: set of these properties: in js 
Javascript :: JSON Using Its Own Property To Get Promise Value 
Javascript :: Constructor for blockchain 
Javascript :: force browser reload page from server javascript 
Javascript :: map sord elo 
Javascript :: array operations = map, filter, find, reduce, some, every, indexOf 
Javascript :: save to text or html file very good 
Javascript :: es6 javascript return types 
Javascript :: how to check bot channel permissions 
Javascript :: winston transport file another directory 
Javascript :: backbone view 
Javascript :: file path to blob javascript 
Javascript :: how to run json server 
Javascript :: inline css in react js 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =