2014-01-15 4 views
2

다음과 같은 내용이 있습니다. 여기에 제가 간과할만한 간단한 해결책이 있습니다. 모델에 데이터를로드하지만 입력 필드를 업데이트하지 않습니다.Angular JS - 모델이 숫자 입력 필드를 업데이트하지 않습니다.

<div ng-app> 
    <h2>Testing</h2> 
    <div ng-controller="MyCtrl"> 
    From: <input name="Price" type="number" ng-model='object.number["From"]' /> 
    To: <input name="Price" type="number" ng-model='object.number["To"]' /> 
    </div> 
</div> 

그리고 자바 스크립트 :

http://jsfiddle.net/pCnfH/6/

+0

당신이 오류를받을 수 있나요을? – putvande

답변

5

당신은 type="number"의 수 입력을 제약하지만, 문자열로 값을 설정하는 : $scope.object['number'].To = "5";

function MyCtrl($scope) { 
    $scope.object = {number : {}}; 
    $scope.object['number'] = {From: null, To: null} 
    console.log($scope.object['number']); 

    $scope.loadPrice = function(){ 
     $scope.object['number'].From = "5"; 
     $scope.object['number'].To = "5"; 
    } 

    $scope.loadPrice(); 
    console.log($scope.object['number']) 

} 

는 바이올린을 포함

$scope.object['number'].From = 5; 
$scope.object['number'].To = 5; 

updated fiddle

또는 개수 제한 제거 : 0 그래서 당신은 숫자에 값을 설정하려는 중 that fiddle

+0

감사합니다. 내 부분에 대한 상당한 감독. – SoluableNonagon

관련 문제