JavaScript How to resume counter from last ended resume for counter sales,resume for counter person,resume of

You can use something like local storage in order to store the counter value in between sessions. Replace var counter = 0; with something like

var counter; 
if(localStorage['counter'] != undefined){
    counter = JSON.stringify(localStorage['counter']).value;
}
else{
    counter = 0;
} 

Note that you should save your counter as a property of an object, like localStorage['counter'] = {value: 5} otherwise your index will be cast to a string.

This would work after opening / closing the page. If you were talking about maintaining the counter past the scope being destroyed (say on a page navigation), then you could use an angular service, although using localStorage can also work in this case.

Answer:1

If you want to save the counter value so that it continues from the last value on reload you could use a simple service to hold the value. If you want to persist this value in local storage or a cookie you could extend the function to that.

    angular.
    module('myServiceModule', []).     
    factory('counterService', [function() {
       var _counter = 0;

       function _get() {        
                return _counter;            
        }

       function _set(value) {
               _counter = value;
       }


        return {
            get: _get,
            set: _set
        }
     }]);

The main changes to your controller would be to get the counter starting value from the service. Then update the service with the changed counter value.

var app = angular.module('myapp', ['ngSanitize', 'myServiceModule']);

app.controller('AddCtrl', function ($scope, $compile, counterService) {
$scope.singleFields = [];
    var counter = counterService.get(); //gets the current value from service
    for(var i =0; i < counter; i++){
      $scope.addNew_SingleField(i);
    }

    $scope.addNew_SingleField = function (index) {
        $scope.singleFields[counter] = {single: 'untitled'};
        var singlehtml = '<div ng-click="selectSingle(singleFields[\'' + counter + '\'])">\n\
<label>{{singleFields[' + counter + '].single}}</label>\n\
<input type="text"></div>';
        var single = $compile(singlehtml)($scope);
        angular.element(document.getElementById('drop')).append(single);
        ++counter;
        counterService.set(counter); //make sure to update the stored value
    };
    $scope.selectSingle = function (val) {
        $scope.singleField = val;
        $scope.showName = true;
    };
});
Answer:2

Says I have multiple of class named item. <div class="item"></div> <div class="item"></div> <div class="item"></div> But I only want to show one, sequence doesn't'...

Says I have multiple of class named item. <div class="item"></div> <div class="item"></div> <div class="item"></div> But I only want to show one, sequence doesn't'...

  1. select only single checkbox
  2. select options only single values
  3. abap select option only single values

I'm trying to add a class to the anchor of the current URL in the menu navigation in order to differentiate it. I've done research and using this snippet 'http://' + window.location.hostname + window....

I'm trying to add a class to the anchor of the current URL in the menu navigation in order to differentiate it. I've done research and using this snippet 'http://' + window.location.hostname + window....

I'm starting to learn ReactJS and I'm following instructions in a book on getting started. My directory structure looks like this: app/App.js node_modules index.html package.json webpack.config.js I ...

I'm starting to learn ReactJS and I'm following instructions in a book on getting started. My directory structure looks like this: app/App.js node_modules index.html package.json webpack.config.js I ...

  1. script5022 syntax error reactjs
  2. script1002 syntax error reactjs
  3. reactjs syntax error unexpected token
  4. script1002 syntax error ie11 reactjs

Without any common JS libraries, how can I hash a password before sending it? <form> <input type="password" id="pwd" name="password" /> <input onclick=" var val = document....

Without any common JS libraries, how can I hash a password before sending it? <form> <input type="password" id="pwd" name="password" /> <input onclick=" var val = document....

  1. simple password hash
  2. c# simple hash password
  3. java simple password hash
  4. php simple password hash
  5. python simple password hash
  6. cms made simple password hash
  7. simple membership provider password hash
  8. cms made simple password hash decrypt