Reputation: 145
I have an AngularJS Select control on the page, the options are bounded dynamically based on rest query. On initial page load I can see the Select options. But as soon as I select one option, the Select control options vanish (getting emptied). If I do page refresh (browser refresh) then I can again see the options.
How to ensure the Options are always bound to select control even after selecting a value?
<select id="ddlLanguage" class="input-block-level" ng-model="languagedata" ng-options="rows1.Language for rows1 in languagedata" ></select>
myAngApp.controller('myController', function ($scope, $http) {
$http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('LangHelpFiles')/items?$select=Language",
headers: { "Accept": "application/json;odata=verbose" }
}).success(function (data, status, headers, config) {
$scope.languagedata= data.d.results;
}).error(function (data, status, headers, config) {
alert(status);
});//end http
});//end controller
Upvotes: 0
Views: 75
Reputation: 483
<select id="ddlLanguage" class="input-block-level" ng-model="language" ng-options="rows1.Language for rows1 in languagedata" ></select>
myAngApp.controller('myController', function ($scope, $http) {
$http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('LangHelpFiles')/items?$select=Language",
headers: { "Accept": "application/json;odata=verbose" }
}).success(function (data, status, headers, config) {
$scope.languagedata= data.d.results;
$scope.language = $scope.languagedata[0];
}).error(function (data, status, headers, config) {
alert(status);
});//end http
})
Upvotes: 0
Reputation: 662
ngModel="languagedata"
is causing the issue. When you select an options, languagedata gets set to the value of the option selected and hence the options disappears.
If you bind some other variable in scope to the option then that will resolve the issue.
Upvotes: 4