I have populated the select box data dynamically and after setting in session those values must be selected even the page reloads
The code that populates the select box options is using ajax get method
else if (value.sourceType > 0) {
$('#SOURCE_TYPE').append('<option data-ng-value="' +
value.sourceName +'">'+ value.sourceName + '</option>');
}
1.The selected session value should place in the selection box
Script
var app = angular.module("app", ['ngMessages']);
app.controller("quotationController",
function($scope,$window) {
$scope.quotation =[];
$scope.contactId = null;
$scope.quotation.drpContactType=$window.sessionStorage.getItem( 'drpContactType' );
$scope.quotation.sourceType = $window.sessionStorage.getItem('sourceType');
$scope.submit = function(){
$window.sessionStorage.setItem('drpContactType',$scope.quotation.drpContactType);
$window.sessionStorage.setItem('sourceType', $scope.quotation.sourceType);
};
fnendtmotoronload();
});
function fnendtmotoronload() {
var status = true;
var contactId = document.getElementById("CONTACT_TYPE").value;
var CONTEXT_PATH = '<%=request.getContextPath()%>/';
$.ajax({
type : "GET",
url : CONTEXT_PATH + "quotationDrop",
data : contactId,
contentType : 'application/json; charset=utf-8',
dataType : 'json',
success : function(result) {
$.each(result, function(index, value) {
if (value.contactType > 0) {
$('#CONTACT_TYPE').append(
'<option data-ng-value="' + value.contactName + '">'
+ value.contactName + '</option>');
} else if (value.sourceType > 0) {
$('#SOURCE_TYPE').append(
'<option data-ng-value="' + value.sourceName + '">'
+ value.sourceName + '</option>');
}
});
}
});
return status;
}
HTML
<div class="col-sm-8">
<select ng-model="quotation.sourceType" ng-option="{{quotation.sourceType}}" required id="SOURCE_TYPE"
class="form-control">
<!-- <option selected="selected" value="0">--SELECT--</option> -->
</select>
Data From DB
{
"contactType": 0,
"contactActiveStatus": "\u0000",
"createdBy": 0,
"sourceType": 2,
"accountCode": 0,
"sourceName": "ADMIN",
"newIcNo": 0,
"businessRegNo": 0,
"oldIcNo": 0,
"quotationID": 0,
"nameddriversno": 0,
"namedage": 0,
"extracoverageid": 0,
"mpaid": 0
},