When choosing a default value from a dynamically populated dropdown using JSON data, I attempted to use regCtrl.screeningTypeList[0] without success.
<select ng-init="regCtrl.user.screeningType.screeningTypeId=regCtrl.screeningTypeList[0]" ng-model="regCtrl.user.screeningType.screeningTypeId" ng-change="regCtrl.getType(regCtrl.user.screeningType.screeningTypeId)"
ng-options="sctype.screeningTypeId as sctype.screeningType for sctype in regCtrl.screeningTypeList"
class="form-control field-size ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched" name="screeningType"
id="screeningType" required >
<!-- <option value="">--SELECT--</option> -->
<!-- <option value="{{sctype.screeningTypeId}}">{{sctype.screeningType}}</option> -->
</select>
The above code snippet represents the AngularJS logic for fetching and displaying JSON data.
function getScreeningTypeList(){
$http({
method: 'GET',
url: 'master/getAllScreeningTypeMast'
}).success(function(response){
vm.screeningTypeList=response.result;
}).error(function(resp){
});
}
This is an example of controller-related code where the 'vm' value is initialized at the beginning.
RegistrationController.$inject = ['$http','LookupService','$filter'];
function RegistrationController($http,LookupService,$filter){
var vm = this;
}