如何在angularjs中存储表的变量值

时间:2017-08-21 14:49:47

标签: javascript jquery angularjs html5

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <title>User Info</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<body data-ng-app="MyAPP" ng-controller="myController">

    <div>

        <h1><u>User Information </u></h1>

        <table style="width 100%" align="center">
            <caption>Enter the information below</caption>
            <tr>
                <th>Entry</th>
                <th>Input</th>
                <th>Input Stored</th>
            </tr>
            <tr>
                <td>Enter Your id </td>
                <td><input type="number" ng-model="id" placeholder="Enter 4 digit id here" pattern="[1-9]{1}[0-9]{3}"></td>
                <td><span ng-bind="id"></span></td>
            </tr>
            <tr>
                <td>Enter your full name </td>
                <td><input type="text" ng-model="name" placeholder="Enter full name here" pattern="[a-zA-Z\s]+"></td>
                <td><span ng-bind="name"></span></td>
            </tr>
        </table>
    </div>
    <div class="btn-group" align="center">
        <button type="button" ng-click="myFunction()" id="one" class='btn btn-default btn-success btn-lg btn1'>Save Entry</button>
        <button type="button" ng-click="close_window()" id="two" class='btn btn-default btn-success btn-lg btn2'>Exit</button>
    </div>

    <script>
        var admin = angular.module('MyAPP', []);
        admin.controller('myController', function ($scope) {
                    $scope.myFunction = function () {
                        var change = document.getElementById("one")
                        if (change.innerHTML == "Save Entry") {
                            change.innerHTML = "Saved!";
                        } else {
                            change.innerHTML = "Save Entry";
                        }
                    }
                    $scope.close_window = function () {
                        if (confirm("Close Window?")) {
                            close();
                        }

                    });

    </script>
</body>

</html>

我正在尝试使用localStorage保存在字段中输入的内容,以便我以后可以显示它。但是只要我添加控制器字段,按钮就会停止工作并且不会执行它们的功能。另外我如何存储这些变量,在代码中有4个变量,以便我可以在表中再次显示它们?

0 个答案:

没有答案