Udhayan Nair
Udhayan Nair

Reputation: 552

Binding a SELECTED option in a laravel blade with laravel foreach and if statement

so i have this block of code that goes like such;

<div class="form-group">
    <div class="row">
      <div class="col-md-12">
        <select class="form-control" ng-model="report.outlet">
          @foreach ($grSite as $pSite)
          @if($jsnUser['selectedSite'] == $pSite['iid'])
            <option selected value="{!! $pSite['iid'] !!}">{!! $pSite['profile']['firstName'] !!}</option>
          @endif
          @endforeach
        </select>
      </div>
    </div></div>

so now here's the problem, when i load the page, all conditions are met, however my option is not automatically selected, it is selected on load, for like 0.5 seconds, and suddenly the select input just goes blank. why is this? also, i've already tried using an @else statement, but it does not work as well. any help would be much appreciated! if it's not clear yet, i'm using a laravel blade template, binding with angular, but this part is purely laravel.

Upvotes: 0

Views: 861

Answers (1)

EddyTheDove
EddyTheDove

Reputation: 13259

It won't be selected because you are using ng-model. In your angular controller you have to give report.outlet a default value which is part of the options. Then according to that value, the option will be selected by default.

The reason it's selected for 0.5 is because angular isn't ready yet. as soon as Angular is ready, it goes blank.

Upvotes: 1

Related Questions