JpDevs JpDevs - 1 month ago 20
AngularJS Question

ng-if in select option selected tag

I am developing Angular JS application and I want to make a select option like below.

<select class="form-control" ng-model="rc.status" ng-init="rc.status=1">
<option value="1" selected="selected">Active</option>
<option value="0" selected="">Inactive</option>
</select>


I want to make active when the ng-model rc.status becomes 1 and inactive when 0.

How can I do that without doing ng-repeat.

Because I generating this view from laravel and binding the html with Angular js

Answer

Here is example that select dropdown value as per rc.status

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="">
  <select class="form-control" ng-model="rc.status" ng-init="rc.status=1">
    <option value="--Select--">--Select--</option>
    <option value="1">Active</option>
    <option value="0">Inactive</option>
  </select>
  <br><br>
  <div>Status : {{rc.status}}</div>
</div>

Comments