angularjs - ng-model is not passing through correct value -
i have select element in users can select orderby filter,
%select{ "ng-change" => "select()", "ng-model" => "selecteditem", "ng-options" => "option.sortby option in listofoptions"}
this listofoptions
$scope.listofoptions = [ {sortby: 'release date', value:'release_date'}, {sortby: 'newly added', value:'created_at'} ];
and select
function,
$scope.select = function(){ console.log($scope.selecteditem.value) }
in view select box shows both release date , newly added options, when select 1 of them error,
typeerror: cannot read property 'value' of undefined
so looks $scope.selecteditem undefined, can't figure out why.
well did plunker , select works expected
app.js:
$scope.listofoptions = [{ sortby: 'release date', value: 'release_date' }, { sortby: 'newly added', value: 'created_at' }]; $scope.select = function() { console.log($scope.selecteditem.value) }
index.html:
<select ng-change="select()" ng-options="option.sortby option in listofoptions" ng-model="selecteditem"></select> <p>{{selecteditem}}</p>
can provide angular version ?
Comments
Post a Comment