2015-07-01 32 views
0
//.js 
    $scope.scopeObject = { 
     "a":{}, 
     "b":{}, 
     "c":{}....... 
    } 
//html 
    <div> 
    <select ng-model="scopeModal" ng-options="key for (key,value) in scopeObject" ng-change = "getKey(group)"></select> 
    </div> 
//js 
$scope.getKey = function(group){ 
console.log(group)//undefined 
} 

在這種情況下,組中的功能是未定義... 我如何獲得關鍵的價值,我的功能? tyNG選項,如何讓鍵值功能(angularJS)

+1

什麼是'group'你的情況? –

+0

* – Vladimir

回答

0

您應該將scopeModal傳遞給change函數。你可以看看下面的代碼片段。

angular.module("myApp", []) 
 
    .controller("myCtrl", ["$scope", function($scope) { 
 
    $scope.scopeObject = { 
 
     "a": {id: "a", value: "a"}, 
 
     "b": {id: "b", value: "b"}, 
 
     "c": {id: "c", value: "c"} 
 
    } 
 
    $scope.getKey = function(group) { 
 
     console.log(group) //undefined 
 
    } 
 
    }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
    <select ng-model="scopeModal" ng-options="key for (key,value) in scopeObject" ng-change="getKey(scopeModal)"></select> 
 
    {{scopeModal}} 
 
</div>