Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-selected true but not selecting

Tags:

angularjs

so, i have a select list and I am trying to select the item dynamically. The thing is, even doe the expression is evaluated to "true" the option is still not being selected

<label for="articlePage">Page:</label>
<select class="form-control pageList" name="articlePage" required="" ng-model="article.page_ID">
    <option ng-repeat="page in pages" ng-selected ="{{page.id == article.page_ID}}" value={{page.id}}>{{page.name}}</option>
</select><br>

the scope(pages):

$scope.pages = [
        { name: "Home",                 id: "1" },
        { name: "Plugs",                id: "2" },
        { name: "Pack Bedding",         id: "3" },
        { name: "Pot Bedding",          id: "4" },
        { name: "Poinsettias",          id: "5" },
        { name: "Sales",                id: "6" },
        { name: "Process Quality",      id: "7" },
        { name: "Environment",          id: "8" },
        { name: "Process Technology",   id: "9" },
        { name: "Process Control",      id: "10" },
        { name: "Infrastructure",       id: "11" },
        { name: "News",                 id: "12" },
        { name: "About",                id: "13" },
        { name: "Contact",              id: "14" },
        { name: "Find Us",              id: "15" },
        { name: "Key Personnel",        id: "16" },
        { name: "Recruitment",          id: "17" },
        { name: "Legal Information",    id: "18" },
        { name: "Hidden",               id: "19" }
];

there is also an service that is retrieving my articles, i know i get that right and like i said, the expression is being evaluated. here is a print screen to prove that:

enter image description here

does anyone have any idea why the option isn't being selected?

Thank you! :)

like image 862
Spluf Avatar asked Mar 07 '16 16:03

Spluf


1 Answers

You don't need expression inside the ng-selected! Try this:

<label for="articlePage">Page:</label>
    <select class="form-control pageList" name="articlePage" required="" ng-model="article.page_ID">
    <option ng-repeat="page in pages" ng-selected ="page.id == article.page_ID" value="{{page.id}}">{{page.name}}</option>
</select><br>
like image 74
Han Arantes Avatar answered Oct 02 '22 19:10

Han Arantes