javascript - With Angular - How to Pre-Select a Option that gets repeated out if a value exist? -


so trying pass parameter in url page select being repeated out. parameter passing customerprofile.id. trying find customerprofile.id in select options , select it. how go that? if customerprofile.id exist select corresponding option if not default. ids being spit out 1,2,3,4,5, etc... if need more info let me know.

here select:

<div class="form-group" id="testpick">    <label for="field_customerprofile">customerprofile</label>    <select class="form-control" id="field_customerprofile" name="customerprofile"      ng-model="rentalagreement.customerprofile"      ng-options="customerprofile customerprofile.lastname customerprofile in customerprofiles track customerprofile.id">       <option value=""></option>    </select> </div> 

tried 1 being replaced later parameter.

angular.element('div#testpick select').val('1'); 

in ng-model store customer id instead of whole customer object, i.e. replace ng-options="customerprofile ... ng-options="customerprofile.id ...:

<select class="..." id="..." name="..." ng-model="rentalagreement.customerprofileid" ng-options="customerprofile.id customerprofile.lastname customerprofile in customerprofiles track customerprofile.id">     <option value=""></option> </select> 

then idea set variable binded ng-model, i.e. rentalagreement.customerprofile, parameter value url, customer id. if setted value matches 1 of options, select list point on value. retrieve url parameter injecting $location in controller, , $location.search():

controller

assuming url parameter named customerid:

$scope.rentalagreement = {     customerprofileid: $location.search().customerid } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -