0

i have a simple page with a table and a select. I need to apply a filtering with a default value preselected in the html select. The filter need to be applied immediately, when the page finish the loading phase . Here's my code:

The select:

<select class="span2" ng-model="fiASS">
        <option></option>
        <option>Ftse Mib</option>
        <option ng-selected="selected">Nasdaq</option>
        <option>Dow Jones</option>
        <option>Dax</option>
        <option>Cac40</option>
    </select>

The repeater and filters

<tr ng-repeat="obj in titoliASS | filter:filtroASS | filter:exchange| filter:poASS | orderBy:predicateASS:reverseASS">
            <td>{{obj.TITOLO}}</td>
            <td class="hidden-phone">{{obj.INDICE}}</td>
            <td>{{obj.POSIZIONE}}</td>
            <td class="hidden-phone">{{obj.PREZZO}}</td>
            <td class="hidden-phone">{{obj.S1}}</td>
            <td class="hidden-phone">{{obj.R1}}</td>
            <td class="hidden-phone">{{obj.S2}}</td>
            <td class="hidden-phone">{{obj.R2}}</td>
            <td><a href="Technical_Analysis.html?idtitolo={{obj.ID}}&titolo={{obj.TITOLO}}"><i class='icon-signal xmlcursor'></i></a></td>
        </tr>

The preselection for a default value in the select works but the filter is not applied. The filter is applied only when i change value on the select. I hope the prob is clear.

Thx.

1 Answer 1

2

You've got a couple of problems. First, your ng-selected expression doesn't match your match your model.

Second, even if it did, it won't pick it up from the html; the fiASS variable would need to be set on the scope in your controller.

Assuming, however, that the data for the select is static, you could just encode it in your controller instead of the HTML and use ng-options:

<select ng-model='fiASS' ng-options='index for index in indices'></select>

And in your controller:

$scope.fiASS = 'Nasdaq';
$scope.indices = ['Ftse Mib', 'Nasdaq', 'Dow Jones', 'Dax', 'Cac40'];

This would set up the models correctly once the code is loaded, and your filters (assuming they rely on the value of fiASS) should be applied.

Here's a fiddle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.