Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default value in angucomplete

Tags:

angularjs

I am using angucomplete-alt to show dropdown search. Its working fine.But in one case I want to set its value from controller. I tried

 $scope.selectedCustomer.title = $scope.customerList[1].businessName

& also

$scope.selectedMerchant = $scope.merchantList[1]

But the both didn't work. In the angucomplete-alt documentation its written that there is two way binding. Can any one help me out in displaying default selection..

like image 562
Anita Avatar asked Mar 11 '15 06:03

Anita


2 Answers

Not sure if you ever found an answer to this but I thought I would share how I achieved this.

<angucomplete-alt id="owner"
placeholder="[email protected]"
pause="400"
selected-object="subscription.EmailAddress"
initial-value="{{subscription.EmailAddress}}"

Initial value accepts a string value, using angular syntax I was able to generate this from the controller using curly brackets.

Hope this helps.

like image 161
Brett Smith Avatar answered Dec 01 '22 10:12

Brett Smith


I was using angucomplete-alt along with ui-bootstrap's modal I tried a lot, ended up doing this:

$timeout(function(){
    $scope.$broadcast('angucomplete-alt:changeInput', 'myType', myTypeVal);
}, 200);

..and the html was

<angucomplete-alt id="myType" placeholder="My Type"
                    pause="400" selected-object="myTypeSelectedFn"
                    remote-url="/searchMyType"
                    remote-url-request-formatter="searchMyTypeFn"
                    search-fields="name" title-field="code"
                    input-class="form-control form-control-small"
                    match-class="angucomplete-highlight"
                    name="myType" minlength="1" field-required="true"
                    field-required-class="alert-danger"
                    text-searching="Fetching.." auto-match="true" 
                    ng-model="modifiedMy.type"/>
like image 39
Anand Rockzz Avatar answered Dec 01 '22 09:12

Anand Rockzz