Search code examples
angularjsng-options

How to use ng-if and ng-options together in angular 1


I used below syntax to display username. I want to display username when (user.company==userData.company) in the below list. Please help me to achieve this.

<select ng-options="user.FirstName+' 'user.LastName for user in companyUsers | orderBy:'FirstName' track by user.Id" ng-if="user.company==userData.company" ng-model="selectedUser" ng-change="loadListNew()">
</select>

Solution

  • Using ng-if="user.company==userData.company" does not work because that would be applied to the select element.

    Filters Options

    Instead, you can use a filter directly inside your ng-options like in this example.

    Filter Document

    https://docs.angularjs.org/api/ng/filter/filter