Initial ng-model value not set in select

前端 未结 4 1237
庸人自扰
庸人自扰 2021-02-05 06:46

I have an enum (I code using TypeScript):

export enum AddressType
{
    NotSet = 0,

    Home = 1,
    Work = 2,
    Headquarters = 3,

    Custom = -1,
}
         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 07:00

    Found the problem:

    The array returned by Ctrl.getAddressTypes() was an array of strings:

    ["0", "1", "2", "3", "1"]
    

    and what was stored in Ctrl.type was of type number.

    AngularJS compares the array supplied to ng-options to the value supplied to ng-model using the '===' operator. 3 does not equal to "3" in that case - that's why it did not work.

提交回复
热议问题