在HTML中使用localStorage中的数据

时间:2016-11-20 20:13:11

标签: javascript html angularjs forms

使用高级设置页面。 我尝试,根据所选的radiobatton更改单位的名称(单位本身在查询中变化(!))。 例如:

  $scope.savecity=function(){
                localStorage["var"]=$scope.username;
                localStorage["SystemOfNumbers"]=$scope.SystemOfNumbers;
  <label>
      <input type="radio" ng-model="SystemOfNumbers" value="metric">
      Metric
    </label>
      <label>
      <input type="radio" ng-model="SystemOfNumbers" value="imperial">
      Imperial
    </label><br/>

   <button ng-click='savecity()'>Submit</button>

  $scope.savecity=function(){
            localStorage["var"]=$scope.username;
            localStorage["SystemOfNumbers"]=$scope.SystemOfNumbers;
            if (localStorage[SystemOfNumbers]="metrical"){
              localStorage["icon"]="°C"
            }
            else {
                localStorage["icon"]="°F"
            }
}

popup.html:

 {{vm.data.list[0].temp.day}}{{localStorage["icon"]}}

即,激活选择器,改变转换方式,但不改变显示单元。

来源:http://zalil.su/9855055

1 个答案:

答案 0 :(得分:0)

答案: 您可以在选项页面上输入城市名称(但是英语)

(function(angular) {
  'use strict';
angular.module('scopeExample', [])
  .controller('MyController', ['$scope', function($scope) {
    $scope.username = '';

    $scope.sayHello = function() {
      $scope.greeting = 'Hello ' + $scope.username + '!';
    };
    $scope.savecity=function(){
                localStorage["var"]=$scope.username;
                localStorage["SystemOfNumbers"]=$scope.SystemOfNumbers;

    };

  }]);
})(window.angular);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
-<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Angular JS</title>
   <link rel="stylesheet" type="text/css" href="style.css">
  <script src="angular.min.js"></script>
    <script  src="weather 2.js"></script>
  </head>
  <body ng-app="scopeExample">
    <div ng-controller="MyController">
    Enter city name:
      <input type="text" ng-model="username">

    <label>
      <input type="radio" ng-model="SystemOfNumbers" value="metric">
      Metric
    </label>
      <label>
      <input type="radio" ng-model="SystemOfNumbers" value="imperial">
      Imperial
    </label><br/>
  
   <button ng-click='savecity()'>greet</button>

    <a href="popup.html">Назад</a>
      </div>
  </body>
  </html>