2014-09-22 3 views
-1

라디오 버튼 목록에 따라 값을 업데이트하는 컨트롤러가 있습니다.AngularJS로 값을 표시하기 전에 값 처리

MyTypes = { 
    "cat": 0, 
    "dog": 1, 
    "cow": 2 
}; 

function MyController($scope) { 
    $scope.value= 1;  //Updated by a radiobuttons list 
} 

<!-- Display --> 
<label >Type ({{value}})</label> 

"1"이 표시됩니다. "개"를 표시하고 싶습니다. html 템플릿 안에서 함수를 호출하는 방법이 있습니까? 이 함수는 value와 연관된 키를 찾습니다.

답변

0

나는 이런 식으로 해왔 :

[snip MyTypes setup] 
function MyController($scope) { 
    var typesById = []; 
    angular.forEach(MyTypes,function(v,k){typesById[+k]=v;}); 
    $scope.typesById=typesById; 
    $scope.value= 1;  //Updated by a radiobuttons list 
} 

<!-- Display --> 
<label >Type ({{typesById[value]}})</label> 
관련 문제