0

So, what I am trying to do is to make a few checkboxes on a page. The idea is that if I check a checkbox and then save the info in Mongo db, then reload the page, then the checkbox I checked earlier should stay checked on reload.

Let me make this Plnkr

If the plnk doesnt load, Let me enter the code as well.

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <script src="https://code.angularjs.org/2.0.0-alpha.45/angular2.js" data-semver="2.0.0-alpha.45" data-require="angular.js@*"></script>
    <script src="app.js" data-semver="2.0.0-alpha.45" data-require="angular.js@*"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body ng-controller="main">
    <label>Test checkbox</label>
    <input type="checkbox" id="" ng-model="test.checkbox" value="test" name="testCheckbox" ng-checked="">
    <br />{{ greeting }}

  </body>

</html>

Please check and let me know a solution, guys!

TIA.

Sarthak Batra
  • 487
  • 2
  • 10
  • 24
  • Remote solution :If you are using Mono db then itialize your vairables first using your Mongo Db or simple local solution could be use local storage or cookies – Shubham Nigam Jan 25 '16 at 11:00

2 Answers2

1

You may need to use localStorage in HTML5.

Below will help you -

keep checkboxes checked after page refresh

Community
  • 1
  • 1
Ankit Tripathi
  • 405
  • 4
  • 13
  • Great. This looks like it would solve my problem. Do you have an example of this using Angular and not Jquery? I'm a noob and would learn quicker if I get exact references. Thanks in advance @AnkitTripathi – Sarthak Batra Jan 25 '16 at 11:11
0

You need to get data from Monogo onload OR you can use localStorage

Vahan
  • 31
  • 4