how to push all values from the txt file to local storage using angular js

筅森魡賤 提交于 2019-12-14 03:17:40

问题


I have a sample application which can store values into local storage when user clicks to local button but i want to all values from the txt file to be in local storage "note2": [] .

Plunker Demo


回答1:


To put your data in localStorage in angularJS you can use the library angular-localForage.

Example:

angular.module('yourModule', ['LocalForageModule'])
.controller('yourCtrl', ['$scope', '$localForage',
    function($scope,$localForage) {
      $localForage.setItem('myName','Olivier Combe').then(function() {
        $localForage.getItem('myName').then(function(data) {
          var myName = data;
        });
      });
 }]);



回答2:


And yes i found a way to do so .,

you can use ng-init='Function name'

here i use a function when a user click the to local button to push a value to local

$scope.cloneItem = function (todo) {
        $scope.$storage.notes.push({
            "price": todo.price,
            "id": todo.id,
            "quan": todo.quan
        });
    }

but i want to store all the values from the txt file to local so i use

ng-init='your js function name' 

this function to call push function so that for every ng-repeat the value would push to local

Example :

<tr ng-repeat="todo in todos" ng-init='cloneItem(todo)'>


来源:https://stackoverflow.com/questions/32689822/how-to-push-all-values-from-the-txt-file-to-local-storage-using-angular-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!