2016-09-16 3 views
-1

내가 JSON 형식으로 데이터가에서 편집 된 값을 가져옵니다 :AngularJS와 같은

"details": { 
    "col1": "value1", 
    "col2": "value2", 
    "col3": "value3", 
    "col4": "value4", 
    "col5": "value5", 
    "col6": "value6", 
    "col7": "value7", 
    "col8": "value8" 
    } 

<div ng-repeat="(key,value) in details"> 
<div>{{key}}:</div> 
<input value="value">{{value}} </input> 

나는 값이 제기 편집 할 경우, 컨트롤러에서 값을 편집 얻을 수있는 방법을?

답변

0

이 당신이 찾고있는 무엇인가 NG 모델

<input type="text" ng-model="value" ng-blur="print(value)" size="30"> 

WORKING DEMO

+0

잘 작동하지만 json도 업데이트하고 싶습니다. – user123

0

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

 
app.controller('appCtrl', function($scope) { 
 
    var details = { 
 
    "col1": "value1", 
 
    "col2": "value2", 
 
    "col3": "value3", 
 
    "col4": "value4", 
 
    "col5": "value5", 
 
    "col6": "value6", 
 
    "col7": "value7", 
 
    "col8": "value8" 
 
    } 
 

 

 
    $scope.details = details; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<body ng-app="myApp"> 
 
    <div ng-controller="appCtrl"> 
 
    <div ng-repeat="(key,value) in details"> 
 
     <label>{{key}}:</label> 
 
     <input ng-model="details[key]"> 
 
    </div> 
 
    <br> 
 
    <br> 
 
    <div>{{details}}</div> 
 
</body>

0

에 결합 변수와 $ 범위를 사용?

이 작업 스 니펫을 사용해보십시오. 값은 텍스트 상자에서 변경된 값에 따라 달라집니다.

@Mahesh Karthu

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

 
app.controller('appCtrl', function($scope) { 
 
    var details = { 
 
    "col1": "value1", 
 
    "col2": "value2", 
 
    "col3": "value3", 
 
    "col4": "value4", 
 
    "col5": "value5", 
 
    "col6": "value6", 
 
    "col7": "value7", 
 
    "col8": "value8" 
 
    } 
 

 

 
    $scope.details = details; 
 
    
 
    $scope.getChangedValue = function(value){ 
 
    console.log("Key :" + value); 
 
    console.log("Value :" + details[value]); 
 
    }; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<body ng-app="myApp"> 
 
    <div ng-controller="appCtrl"> 
 
    <div ng-repeat="(key,value) in details"> 
 
     <label>{{key}}:</label> 
 
     <input ng-model="details[key]" ng-blur="getChangedValue(key)"> 
 
    </div> 
 
    <br> 
 
    <br> 
 
    <div>{{details}}</div> 
 
    </div> 
 
</body>

: 코드 조각 주셔서 감사합니다.