Hi, I am new to angular js and I am working on a local anglarjs storage technique so that the data is saved when updating. Is there a way to remove local storage in one, as well as assign area storage for the model and use the model in html than $ storage.id. I am very new, and please share and help me. thanks
<!DOCTYPE html> <html ng-app="myApp"> <head> <title> </title> <script type="text/javascript" src="angular.min.js"></script> <script type="text/javascript" src="angular-local-storage.js"></script> <script type="text/javascript" src="angular-route.js"> </script> <script> var myApp=angular.module("myApp",['ngStorage','ngRoute']); myApp.controller('myAppCtrl', ['$scope','$localStorage','$location', function($scope,$localStorage,$location){ $scope.$storage=$localStorage.$default({ myname:"", myid:"", mynumber:"", }); $scope.add=function() { alert("asdsd") delete $scope.$storage.myid; delete $scope.$storage.myname; delete $scope.$storage.mynumber; $location.path("/add"); } }]); myApp.config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider) { $routeProvider. when('/', { templateUrl: 'search.html', controller:'myAppCtrl' }). when('/add',{ templateUrl:'add.html', controller:'myAppCtrl' }). otherwise({ redirectTo: '/' }); }]); </script> </head> <body > <div ng-view>
and my template is listed below.
<script type="text/ng-template" id="search.html"> <button ng-click="add();"> add </button> </script> <script type="text/ng-template" id="add.html"> <div> <input type="text" ng-model="$storage.myname"/></br> <input type="text" ng-model="$storage.myid"/></br> <input type="number" ng-model="$storage.mynumber"/></br> <button ng-click="submit();"> submit </button> <button ng-click="edit();"> view button </button> </div> </script> </body> </html>
source share