javascript—我试图显示一个数组,其中包含来自json文件的数据+我添加的更多数据,但它只显示来自json文件的数据

holgip5t  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(153)

我有一个表单可以从用户那里获取所有数据字段,但是当我试图显示它时,只有json文件数据显示,我无法获取我推送到客户机数组中要显示的数据,我确信数据已添加到客户机数组中,因为我可以在控制台中记录它。
html视图:

<div ng-controller="adminCtrl" class="listClients">
    <h1>Liste des clients :</h1>
      <ul>
        <li ng-repeat="client in clients">
          <h3>{{client.numClient}} - {{client.rue}}</h3>
        </li>
      </ul>
    </div>

app.js

myApp.controller('adminCtrl', ['$scope', '$http', '$location',function($scope, $http, $location){

  //get clients in arr clients
  $http.get("data/clients.json").then(function(response){
      $scope.clients = response.data;
  }); // clients is an array containing all clients from clients.json

  //add newclient
  $scope.addClient = function(){
    $scope.clients.push ({
       numClient: parseInt($scope.newclient.numClient),
       rue: $scope.newclient.rue,
       numRue: parseInt($scope.newclient.numRue),
       codePostal: parseInt($scope.newclient.codePostal),
       localite: $scope.newclient.localite,
       available: true
   });

    $scope.newclient.numClient = "";
    $scope.newclient.rue = "";
    $scope.newclient.numRue = "";
    $scope.newclient.codePostal = "";
    $scope.newclient.localite = "";

  };

}]);

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题