0

我想在我的Values变量中存储文本框的值,但它不保存我不知道为什么有人帮我请?我是新的angularjs这就是为什么我在这里请帮助我我想从文本框的商店价值,我进入我的文本框ff看到下面的图像,但我检查我的控制台文件显示'网站名称'我认为它从我的硬编码价值,但我想从文本数据如何在范围变量中保存文本框的值angularjs

 $scope.form = { 
     site_name: 'Site name', 
     street_address: 'Street address', 
     city: 'City', 
     state: 'state', 
     country: 'country', 
     zip_code: 'zip_code', 
     phone_number: 'phone_number' 

     }; 
     $scope.addRow = function() { 
     $scope.i++; 
     $scope.array = []; 
     for(var i = 0; i < $scope.i; i++) { 
      $scope.array.push(i); 
     } 
    } 
     var checkprofile = $scope.Profile.id; 
     $(".alert").hide();  
      $scope.updateProfile = function() { 

       console.log('updateProfile'); 
      console.log($scope.form); 
$scope.Profile.addresses.push($scope.form); 
      $scope.tempObject={full_name:$scope.Profile.full_name, 
       mobile_number:$scope.Profile.mobile_number, 
      company_name:$scope.Profile.company_name, 
      designation: $scope.Profile.designation,  
      addresses: $scope.Profile.addresses, 

      payment_info: $scope.Profile.payment_info 

      }; 

      $http.put(properties.customerupdate_path + "/"+checkprofile,$scope.tempObject).success(function (response) { 
      // window.location.href = '/customerprofile'; 
       }); 
      }  

我按一下按钮后,输入值“FF”“FF”“FF”在我的文本框...下面的代码不会从文本框获取数据,它让我的上述数值我不“知道为什么

$scope.updateProfile = function() {  
      console.log('updateProfile'); 
     console.log($scope.Values); 

//结果 - > [对象{SITE_NAME = “网站名称”,STREET_ADDRESS =“街 广告礼服”,市= “城市”,更...}]

} 

HTML //

<tr ng-repeat="lines in array"> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.site_name ' name='site_name'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.street_address ' name='street_address'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.city ' name='city'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.state ' name='state'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.country ' name='country'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.zip_code ' name='zip_code'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.phone_number ' name='phone_number'></td>           
</tr> 

更新个人资料

enter image description here

+0

貌似$ scope.values是一个列表,但你使用它作为NG模型 – ngrj

+0

我想对象.... –

回答

1
$scope.values = { 
    site_name: 'Site name', 
    street_address: 'Street address', 
    city: 'City' 
}; 

<tr> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='values.site_name ' name='site_name'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='values.street_address ' name='street_address'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='values.city ' name='city'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='values.state ' name='state'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='values.country ' name='country'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='Values.zip_code ' name='zip_code'></td> 
    <td><input type="text" class="form-control" id="inputDefault" ng-model='values.phone_number ' name='phone_number'></td> 
</tr> 

你不不使用数组来存储变量,而是使用对象。

+0

对象{}数组是空的,当我检查控制台的对象:替换为你的价值观.log($ scope.values); –

+0

你有没有改变你的'ng模型'?切勿使用大写字母作为变量名的第一个字母。看看'td',你可以看到'ng-model =“值。”'而不是'ng-model =“值。” – trichetriche

+0

是的,但是对象是空的 –

0

您正试图遍历一个对象。您的模型应该是一个数组,以支持这一点。剩下的代码就好了。

$scope.Values = [ 
    { 
     site_name: 'Site name', 
     street_address: 'Street address', 
     city: 'City', 
     state: 'state', 
     country: 'country', 
     zip_code: 'zip_code', 
     phone_number: 'phone_number' 
    }, 
    { //next object 
    } 
];