-1

Code in html

<div ng-repeat="cityobj in cityData" class="tabledata">
           <input type="text" ng-value="{{cityobj.temp.humidity}}" ng-model="humidity">
            <div>

In controller

console.log("The value in textfield is",$scope.humidity);

It always give undefined output

4

1 回答 1

0

You don't need ng-value since you already using ng-model

<div ng-repeat="cityobj in cityData" class="tabledata">
       <input type="text ng-model="cityobj.temp.humidity">
 <div>

and then it should work

console.log("The value in textfield is",$scope.cityData[passindex].cityobj.temp.humidity");

DEMO

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);
}

});
<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>

于 2017-12-31T14:06:09.993 回答