I wrote a filter myself and the code is as follows:
app.filter('selected', function() {
return function(input, value) {
var out = "";
if(input == value){
out = "selected";
}
return out;
};
});
The page code is as follows:
<select class="form-control input-sm" style="width: 60px;">
<option {{data.page.pageSize|selected:5}} >5</option>
<option {{data.page.pageSize|selected:10}} >10</option>
<option {{data.page.pageSize|selected:20}} >20</option>
<option {{data.page.pageSize|selected:50}} >50</option>
</select>
But writing it like this doesn’t work now, and it has no effect when pageSize is any value. Can anyone give me some advice? Thanks!
漂亮男人2017-05-15 17:05:19
How about you stop using filter
and change it like this?
<select class="form-control input-sm" style="width: 60px;">
<option ng-selected="data.page.pageSize === 5">5</option>
<option ng-selected="data.page.pageSize === 10" >10</option>
<option ng-selected="data.page.pageSize === 20" >20</option>
<option ng-selected="data.page.pageSize === 50" >50</option>
</select>
phpcn_u15822017-05-15 17:05:19
<select class="form-control input-sm" style="width: 60px;">
<option data-ng-selected="{{data.page.pageSize | selected: 10}}" >10</option>
<option data-ng-selected="{{data.page.pageSize | selected: 20}}" >20</option>
<option data-ng-selected="{{data.page.pageSize | selected: 50}}" >50</option>
</select>
app.filter('selected', function() {
return function(input, value) {
return input == value;
};
})