0

Hi I'm trying to get Angular JS ng-repeat to store information from users, so they can use it to log in with later. Am I doing this right?

.html

<div id='div' ng-controller="usersCtrl">
  <ul>
    <li ng-repeat="x in users">
      {{ x.username + ", " + x.password}}
    </li>
  </ul>
</div>

<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="js/controllers/users.js"></script>
<script src="js/app.js"></script>
<script src="js/main.js"></script>

angular.js

app.controller('usersCtrl', function($scope){
  $scope.users = [
    {username: 'Regie', password: 'Tano'},
    {username: 'Greg', password: 'Mayer'},
    {username: 'Jacob', password: 'Minshall'},
    {username: 'Bank', password: 'Chaiwong'}
  ]
})
4
  • You could create UserService to share data between application.. Commented Apr 29, 2017 at 22:46
  • So basically you want to store usernames and passwords within your JS file, and then render them on the page so anyone can see them? Commented Apr 29, 2017 at 22:46
  • I want to store user info that will be later used to log into the app Commented Apr 29, 2017 at 22:55
  • Possbile duplicate : stackoverflow.com/questions/14206492/… Commented Apr 30, 2017 at 5:08

1 Answer 1

2

You should create Service to do it

     app.factory('myService', function() {
 var savedData = {};
 return {
  set: set,
  get: get
 }
 function set(data) {
     savedData['user']  = data
 }
 function get() {
  return savedData;
 }

Here is plnkr

http://plnkr.co/edit/jfoDRcOSl0hP8ErVlZ3u?p=preview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.