html中的代码
<div ng-repeat="cityobj in cityData" class="tabledata">
<input type="text" ng-value="{{cityobj.temp.humidity}}" ng-model="humidity">
<div>
在控制器中
console.log("The value in textfield is",$scope.humidity);
它始终提供未定义的输出
答案 0 :(得分:0)
由于您已经使用了ng-model
,因此您不需要ng值<div ng-repeat="cityobj in cityData" class="tabledata">
<input type="text ng-model="cityobj.temp.humidity">
<div>
然后它应该工作
console.log("The value in textfield is",$scope.cityData[passindex].cityobj.temp.humidity");
<强>样本强>
var app =angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
$scope.cityData = [{
"city": "Klimovsk",
"temp": {
"humidity":2
}
}, {
"city": "Shalakusha",
"temp": {
"humidity":5
}
}];
$scope.print =function(cityObj){
console.log(cityObj.temp.humidity);
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<div ng-repeat="cityobj in cityData" class="tabledata">
<input type="text" ng-model="cityobj.temp.humidity">
<button ng-click=print(cityobj)>PRINT</button>
<div>
</body>
&#13;