2

table as static possible in angular js?

 2 years ago
source link: https://www.codesd.com/item/table-as-static-possible-in-angular-js.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

table as static possible in angular js?

advertisements

I need to declare an array

and i need to keep each item added to it should remain for there for ever, even if the page is reloaded, is it possible? var arr=[]; arr.push('id');

like this, but stored item should not be replaced.


You can use cookies in AngularJS to maintain the values. FYI, enter link description herea JSFiddle of this using the $cookieStore, two controllers, a $rootScope, and AngularjS 1.0.6. It's on JSFiddle as https://jsfiddle.net/h2fs0han/ as a base if you're messing around with this...

For more information refer - How to access cookies in AngularJS?

<div ng-app="myApp">
  <div id="lastVal" ng-controller="ShowerCtrl">{{lastVal}}</div>
  <div id="button-holder" ng-controller="CookieCtrl">
    <input type="text" ng-model="strText" />
    <button ng-click="AddItem()">Add Item!</button>
  </div>
</div>

 var myApp = angular.module('myApp', ['ngCookies']);
 myApp.controller('CookieCtrl', function($scope, $rootScope, $cookieStore) {
  $scope.strText = "";

  $scope.AddItem = function() {
    var lastVal = $cookieStore.get('lastValue');
    if ($scope.strText) {
      if (!lastVal) {
        $rootScope.lastVal = new Array(); //Default
        $rootScope.lastVal.push($scope.strText);
      } else {
        var newItem = angular.copy(lastVal);
        newItem.push($scope.strText);
        $rootScope.lastVal = newItem;
      }
      $cookieStore.put('lastValue', $rootScope.lastVal);
    }
  };
});

myApp.controller('ShowerCtrl', function() {});


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK