Check out this HTML snippet:
<select style="width: 100%;" ng-model="vm.orgType" ng-model-options="{getterSetter: true}" ng-options="orgType as orgType.ORGANIZATION_TYPE for orgType in vm.orgTypes">
</select>
Now, let's take a look at the getter/setter function:
function orgType(selectedType) {
if (arguments.length == 0)
return orgType.selectedOrgType || { ORGANIZATION_TYPE: 'Organization Type', ORGANIZATION_TYPE_ID: null };
orgType.selectedOrgType = selectedType;
if (selectedType.ORGANIZATION_TYPE_ID) {
if (vm.registrant.StakeholderOrgs[0])
vm.registrant.StakeholderOrgs[0] = selectedType.ORGANIZATION_TYPE_ID;
else
vm.registrant.StakeholderOrgs.push(selectedType.ORGANIZATION_TYPE_ID);
} else
vm.registrant.StakeholderOrgs.splice(0);
}
This specific line of code is causing an infinite digest loop error:
return orgType.selectedOrgType || { ORGANIZATION_TYPE: 'Organization Type', ORGANIZATION_TYPE_ID: null };
Allow me to explain my intention with this setup. I aim to add the ID to a list upon making a selection. While I could simply use an ng-model
on a variable like selectedOrgType
and handle logic in an ng-change
, I prefer structuring a dropdown without creating extra model variables. My approach involves utilizing a getter/setter for more streamlined functionality. Despite setting one of vm.orgTypes
to
{ ORGANIZATION_TYPE: 'Organization Type', ORGANIZATION_TYPE_ID: null }
as the default value, I encountered the unexpected digest error and am puzzled by its origin.