I'm encountering an issue while trying to upgrade my ng-model within a selection feature.
Here is the HTML code I am currently using:
<div ng-app>
<div ng-controller="Ctrl">
<select ng-model="viewmodel.inputDevice"
ng-options="i.label for i in viewmodel.inputDevices">
</select>
</div>
</div>
Below is the JavaScript code I have written:
function Ctrl($scope) {
// view model
$scope.viewmodel = new function () {
var self = this;
var elem1 = {
value: '1',
label: 'input1'
};
var elem2 = {
value: '2',
label: 'input2'
}
self.inputDevices = [elem1, elem2];
self.inputDevice = {
value: '1',
label: 'input1'
};
};
}
You can check out the working example on JSFiddle
My goal is to set the values of inputDevice to match those of the first device in the inputDevices array.
While passing elem1 directly would solve it, I need to store the selection in Local Storage and then restore it to the ng-model object. Any suggestions or tips are highly appreciated!
Thank you