0

I have this piece of code

<select id="headers" ng-model="importHeader.systemHeaders">
<option ng-repeat="requiredHeaders in vCtrl.wizard.costs.headerData.headers" value="{{requiredHeaders}}"  ng-selected="vCtrl.wizard.costs.changed(importHeader.headerName,requiredHeaders.displayName)">{{requiredHeaders.displayName}}
</option>
</select>

All i'm doing is looping through a set of headers and checks if the value of the imported Header is the same on what if required and it automatically selects it. It works fine, But my problem is that it won't add the systemHeaders in my importHeaders object declared on the ng-model

I need a way to trigger the change event of this select. I know that when changing the seletion programmatically it won't trigger the ngChange event.

i tried creating a function:

changed: function(val1,val2){
        if (val1 == val2){
            angular.element('#headers').change();
                return true;
        } else {
            return false;
        }

}

but it gets me an $apply is already in progress error.

Thanks in advance.

Yaje
  • 2,753
  • 18
  • 32

1 Answers1

0

Check this condition before change the header line

if($scope.$$phase)
{
angular.element('#headers').change();
}

And read this discussions : What is $$phase in AngularJS?

Community
  • 1
  • 1
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234