How can I make a <select> dropdown in AngularJS default to a value in localstorage? -


i have <select> populating list of values. works , see expected list. have value set locally stored value if available.

i have code below. when run code number after type in label changes match in localstorage select box not change.

getcontenttypeselect: function ($scope) {     entityservice.getentities('contenttype')         .then(function (result) {             $scope.option.contenttypes = result;             $scope.option.contenttypesplus = [{ id: 0, name: '*' }].concat(result);             $scope.option.selectedcontenttype                   = localstorageservice.get('selectedcontenttype');         }, function (result) {             alert("error: no data returned");         }); },  <span class="label">type {{ option.selectedcontenttype }}</span>    <select        data-ng-disabled="!option.selectedsubject"        data-ng-model="option.selectedcontenttype"        data-ng-options="item.id item.name item in option.contenttypesplus">        <option style="display: none" value="">select content type</option>    </select> 

here code have sets value in localstorage:

    $scope.$watch('option.selectedcontenttype', function () {         if ($scope.option.selectedcontenttype != null) {             localstorageservice.add('selectedcontenttype',                   $scope.option.selectedcontenttype);             $scope.grid.data = null;             $scope.grid.selected = false;         }     }); 

here data stored in contenttypesplus:

0: object id: 0 name: "*" __proto__: object 1: b id: 1 name: "page" __proto__: b 2: b id: 2 name: "menu" __proto__: b 3: b id: 3 name: "content block" __proto__: b 

how can make select box go localstorage value if there one?

update

still hoping answer , happy accept if person can me. answer given not complete , still waiting more information. hoping can give me example fits code. thanks

i think need make sure selectedcontenttype needs id field of option object according comprehension expression defined in select directive.

the comprehensive expression defined

item.id item.name item in option.contenttypesplus 

item.id actual value stored in ng-model option.selectedcontenttype


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -