请检查我的plunk 当我使用按钮时它工作正常但我想要与下拉列表相同的功能。
请解释我如何撰写onChange()
或编辑插件
代码:
HTML:
<select ng-options="d for d in opt2" ng-model="varun" ng-change="onchange()">
<option value="">Select One</option>
</select>
JS:
$scope.order = function(predicate, reverse) {
$scope.friends = orderBy($scope.friends, predicate, reverse);
};
$scope.varun = $scope.opt2[0];
$scope.onchange = function() {
alert($scope.varun);
if($scope.varun == age2 )
{
$scope.friends = orderBy($scope.friends, 'age' , false);
}
else
{
$scope.order('-date',true);
}
}
}
答案 0 :(得分:1)
如果您要查看控制台,请说
ReferenceError:未定义age2
你需要写下来
if($scope.varun == 'age2' )
而不是
if($scope.varun == age2 )