
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
angular-form-persistence
Advanced tools
An Angular module that gives you data persistence using local storage
npm
$ npm install angular-form-persistence
Include angular-form-persistence.js or angular-form-persistence.min.js in your index.html after Angular.
<script src="node_modules/angular-form-persistence.min.js"></script>
Or import angular-form-persistence in your JS.
require('angular-form-persistence');
Add formPersistence to your module's dependencies.
angular.module('app', ['formPersistence']);
.config(function (formPersistenceProvider) {
formPersistenceProvider.setPrefix('dmo');
});
Default prefix: fp.[key]
Directive formPersistence, along with attribute save-data allow you to set the key and the data (respectively) to be stored.
In this example user_form is the key and vm.data is the data that will be stored.
formPersistence will listen for changes in save-data and save the object with every change detected. In the example below, vm.data has some properties bounded to ngModel directive, so every time the user changes the value in the inputs the objects vm.data will be saved under the user_form key.
When the view is reloaded, formPersistence will fill vm.data with the data stored in local storage.
Controller
angular.controller('myController', function(formPersistence) {
'ngInject';
var vm = this;
vm.data = {};
vm.submit = function() {
formPersistence.clearAll();
[...]
};
});
View
<div ng-controller="myController as vm">
<form form-persistence="user_form" save-data="vm.data" ng-submit="vm.submit()">
<label for="username">Username</label>
<input
id="username"
type="text"
name="username"
ng-model="vm.data.username" />
<label for="name">Name</label>
<input
id="name"
type="text"
name="name"
ng-model="vm.data.name" />
<label for="age">Age</label>
<input
id="age"
type="number"
name="age"
ng-model="vm.data.age" />
<button type="submit">
Submit
</button>
</form>
</div>
Get and use the data before is saved. Must return the data that will be saved.
Get and use the data before is loaded into save-data.
Must return the data that will fill save-data.
Controller
angular.controller('myController', function(formPersistence) {
'ngInject';
var vm = this;
vm.data = {};
vm.parseData = function(data) {
// you logic
return data;
};
vm.parseLoadedData = function(data) {
// you logic
return data;
};
});
View
<div ng-controller="myController as vm">
<form form-persistence="user_form" save-data="vm.data" before-save="vm.parseData" before-load="vm.parseLoadedData">
[...]
</form>
</div>
Save data manually in local storage.
| Parameter | Description |
|---|---|
| key | Data key (automatically prefixed) |
| payload | Data to be stored |
| onSave | Optional function to handle the data before is stored |
formPersistence.save(key, payload, onSave);
Load data from local storage.
| Parameter | Description |
|---|---|
| key | Data key (automatically prefixed) |
| onLoad | Optional function to handle the data before is loaded |
Return: Data stored or onLoad results
var data = formPersistence.load(key, onLoad);
Remove data stored with the given key.
| Parameter | Description |
|---|---|
| key | Data key (automatically prefixed) |
formPersistence.clear(key);
Remove all stored data and keys.
formPersistence.clearAll();
FAQs
An Angular module that gives you data persistence using local storage
We found that angular-form-persistence demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.