0

In AngularJS - I have dropdown code as below. type.entityTypeId field is a long data type. The dropdown works fine in the create page and able to insert the 'type.entityTypeId' field into the DB.

But it does not work while reloading the same data in the Edit page with same code.

Is this problem because I have the datatype as Long ?

I have other drop downs working fine in which I have all String data type.

                <div class="form-group">
                <label class="control-label col-md-2 required">ENTITY TYPE</label>
                <div class="col-md-2">
                    <select name="entityType" class="form-control" ng-model="entity.entityType.entityTypeId"
                        required="required">
                        <option value="">Please select</option>
                        <option ng-repeat="type in entityTypes" value="{{type.entityTypeId}}">{{type.entityTypeName}}</option>
                    </select>
                </div>
                <span style="color: red" ng-show="entityAddForm.entityType.$invalid"> <span
                    ng-show="entityAddForm.entityType.$error.required">Entity type is required.</span>
                </span>
            </div>

Updated:

This is a json used to load the drop down data. And you can see the entityTypeId is a number. In other cases it works if the id is a String.

[
{
entityTypeId: 3,
entityTypeName: "Branch of Legal Entity"
},
{
entityTypeId: 1,
entityTypeName: "Legal Entity"
},
{
entityTypeId: 2,
entityTypeName: "Notional Entity"
}
]

2 Answers 2

1

As per the documentation at: https://docs.angularjs.org/api/ng/directive/select

It looks like you do need to use a String at the moment.

Sign up to request clarification or add additional context in comments.

Comments

1

Using numbers should not be an issue. I know that the documentation only uses string, but I'm able to use the same using number.

<div ng-app="myApp" ng-controller="myController">
  <select ng-model="entity.selected">
    <option value="{{ent.entityTypeId}}" ng-repeat="ent in entityTypes">{{ent.entityTypeName}}</option>
  </select>
  Selected entity id  {{entity.selected}}
</div>

angular.module("myApp", [])
  .controller("myController", ["$scope", function ($scope) {
    $scope.entityTypes = [{
      entityTypeId: 3,
      entityTypeName: "Branch of Legal Entity"
    }, {
      entityTypeId: 1,
      entityTypeName: "Legal Entity"
    }, {
      entityTypeId: 2,
      entityTypeName: "Notional Entity"
    }];
    $scope.entity = {
      selected: 3
    };
  }]);

JSFiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.