javascript - how can I use functions as well as variables in the expression for ng-options in Angularjs -
i have 2 select boxes, 1 choose user type (e.g. groups or individual) , 2nd out put of 1st 1 display options choose user/group. there anyway in expressions ng-options
pass function instead of variable :
ng-options="user.id user.description user in getuserlist(usertype)"
where usertype ng-model of first select box
i'm under impression own trials not possible (seem's crash the current tab in chrome , entire application in firefox).
what best approach this. have lot of selects use kind of 2 select box setup nice if avoid copying , pasting.
depending on data, simple as:
<select ng-model="type" ng-options="type type in types"></select> <select ng-model="user" ng-options="user.name user in users[type]" ng-if="type != 'skipped'"></select>
with:
app.controller('appctrl', ['$scope', function($scope) { $scope.types = ['group', 'individual', 'skipped']; $scope.type = $scope.types[0]; $scope.users = { group: [ { id: 1, name: 'foo' }, { id: 2, name: 'bar' } ], individual: [ { id: 3, name: 'foobar' }, { id: 4, name: 'barfoo' } ] }; }]);
demo: http://jsbin.com/eyuq/2/
Comments
Post a Comment