gpt4 book ai didi

angularjs - 不想设置 localStorage 值

转载 作者:行者123 更新时间:2023-12-02 02:57:03 27 4
gpt4 key购买 nike

我在 localStorage 中设置值有问题。我使用 AngularJS 和 Electron。当我更新 refreshTime 时,errorsopacity 的值设置为空。为什么?

$scope.storageLang = localStorage.getItem("language");
$scope.storageMonitors = localStorage.getItem("monitors");
$scope.storageAlarm = localStorage.getItem("alarm");
$scope.storageErrors = localStorage.getItem("errors");
$scope.storageDomain = localStorage.getItem("domain");
$scope.storageOpacity = localStorage.getItem("opacity");
$scope.refreshTime = localStorage.getItem("refreshTime");

$scope.submit = function($event) {
$event.preventDefault();
localStorage.setItem("domain", $scope.storageDomain);
localStorage.setItem("language", $scope.storageLang);
localStorage.setItem("monitors", $scope.storageMonitors);
localStorage.setItem("alarm", $scope.storageAlarm);
localStorage.setItem("errors", $scope.storageErrors);
localStorage.setItem("opacity", $scope.storageOpacity);
localStorage.setItem("refreshTime", $scope.refreshTime);
};

在 HTML 中,我所有的输入都有 ng-model="storageLang"等...

<form ng-submit="submit($event)" style="overflow:hidden">

<div class="field">
<label>{{ lang.domain }}</label>
<input type="text" ng-model="storageDomain" value="{{ storageDomain }}">
</div>

<div class="field">
<label>{{ lang.language }}</label>
<select ng-model="storageLang">
<option value="de" ng-selected="storageLang=='de'">Deutsch</option>
<option value="en" ng-selected="storageLang=='en'">English</option>
<option value="pl" ng-selected="storageLang=='pl'">Polski</option>
</select>
</div>

<div class="field">
<label>{{ lang.monitors }}</label>
<select ng-model="storageMonitors">
<option value="1" ng-selected="storageMonitors==1">1</option>
<option value="2" ng-selected="storageMonitors==2">2</option>
<option value="3" ng-selected="storageMonitors==3">3</option>
<option value="4" ng-selected="storageMonitors==4">4</option>
</select>
</div>

<div class="field">
<label>{{ lang.alarm }}</label>
<select ng-model="storageAlarm">
<option value="1" ng-selected="storageAlarm=='1'">{{ lang.yes }}</option>
<option value="0" ng-selected="storageAlarm=='0'">{{ lang.no }}</option>
</select>
</div>

<div class="field">
<label>{{ lang.errorslimit }}</label>
<input type="number" ng-model="storageErrors" value="{{ storageErrors }}" min="10">
</div>

<div class="field">
<label>{{ lang.opacity }}</label>
<input type="number" ng-model="storageOpacity" value="{{ storageOpacity }}" min="25" step="5">
</div>

<div class="field">
<label>{{ lang.refreshTime }}</label>
<input type="number" ng-model="refreshTime" value="{{ refreshTime }}" min="10" step="1">
</div>

<button class="button expanded neutral">{{ lang.save }}</button>

</form>

最佳答案

问题是我使用了 value="{{ storageOpacity }}" 而我只需要使用 ng-model。除此之外,我需要对一些整数值使用 parseInt...

关于angularjs - 不想设置 localStorage 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48745015/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com