2016-11-21 1 views
0

올바른 속성을 유지하면서 올바른 데이터로 범위를 채우는 데 문제가 있습니다.

json 배열로 ID, 이름 및 시간을 반환하는 작은 PHP 스크립트가 있습니다.

{ 
    "times": [ 
    { 
     "id": "myID", 
     "name": "myName", 
     "time": "40:00:00" 
    }, 
    ...(10 more objects) 
} 

이름으로 이름과 값으로 ID가있는 드롭 다운 요소를 만들고 싶습니다. 나는 ng-repeat 이상으로 이것을 수행했으며 이것은 매우 잘 작동합니다.

<select name="StPl_Code" class="form-control" id="field-stpl-name" ng-model="selected"> 
    <option ng-repeat="i in times" value="{{i.id}}">{{i.name}}</option> 
</select> 

내 문제는 내가 값 속성 여기

의 값을 그대로 유지하면서 다른 입력 필드는 시간 값의 사용 $scope.selected에서 선택한 i을 저장하려는 내 각 코드

입니다
app.controller('auftraegeCrtl', function($scope, $http){ 
     $scope.selected = ''; 
     $http.get('index.php?page=times&json=true').success(function(data, status, headers, config){ 
     $scope.times = data.times; 
     }).error(function(data, status, headers, config){ 
     }); 
    }); 
+0

사용 NG 변화 선택된 객체에 scope.selected $를 설정합니다 : –

+0

I //docs.angularjs.org/api/ng/directive/select 함수를 호출하는 대신 작동하는 인라인 속성이있을 것이라고 생각했습니다. 이걸 확인해 보겠습니다. – mirko911

답변

1

당신은이 같은 NG-옵션 지시문을 사용하는 것이 좋습니다 :

<select name="StPl_Code" class="form-control" id="field-stpl-name" ng-model="selected" ng-options="i.id as i.name for i in times"></select> 
0123을

$scope.selected = {}; 

대신 :

당신은 here

+0

방금 ​​찾았습니다.