AngularJS获取用户信息并存储以供以后使用

时间:2017-04-29 22:42:50

标签: javascript angularjs

您好我正在尝试使用Angular JS ng-repeat存储来自用户的信息,因此他们可以使用它来稍后登录。我这样做了吗?

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'}
  ]
})

1 个答案:

答案 0 :(得分:2)

您应该创建服务来执行此操作

dplyr::filter_

这是plnkr

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