angular.js - Problem using the value of {{}} expression as dom attribute in AngularJS
高洛峰
高洛峰 2017-05-15 17:03:19
0
2
653

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!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
漂亮男人

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_u1582
<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;
      };
    })
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template