从View到AngularJS控制器检索更新的数据

时间:2016-09-19 10:58:57

标签: html angularjs angular

我查找了解决方案,但我找不到合适的解决方案,我需要帮助了解如何将对象数据更新链接到我的控制器。

我有这样的事情:

<body ng-app="SampleApplication">
  <div ng-controller="SampleController">
    <div ng-repeat="catalogItem in catalogItemList">
       <lable>{{catalogItem.name}}</label>
       <input type="text" ng-model="catalogItem.quantity" />

   </div>
</div>
<a href="#proceed">Proceed</a>

在我的控制器中,我有以下内容:

 var myApp = angular.module('SampleApplication',[]);

  myApp.controller('SampleController', ['$scope', function($scope, $http) {
       $http.get('hello.com/').then(function(response){

       $scope.catalogItemList = response.data.catalogItemList;// this works       nicely. The data is displayed on my view nicely
 })
          }]);

编辑catalogItem.quantity之后,我按&#34;继续&#34;按钮,它带我到另一个控制器,但此时,在该控制器中,我看到数量的值没有改变。

       myApp.controller('SampleController', ['$scope', function($scope, $http) {
  $http.post('hello.com/addItems', $scope.catalogItemList);
 }

在服务器端,我注意到收到的catalogItemList包含原始值。 catalogItem.quantity的值保持不变。

请帮助我将html中的数据正确地收集到控制器中?

0 个答案:

没有答案
相关问题