这是我第一次在angularjs上编码一个项目,我似乎无法弄清楚如何隐藏表单,直到在导航栏中单击某个按钮为止。我似乎无法隐藏或正确单击按钮,因为我对angularjs的控制器对象和其他功能不了解。如果您可以,请提供帮助。提前致谢。

继承人代码

    <!DOCTYPE html>




 

<head>
    <meta charset="utf-8"/>


    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" />

    <!-- The main CSS file -->
    <link href="style.css" rel="stylesheet" />

    <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>



<body ng-app>

    <div ng-app="myApp" ng-controller="myCtrl">
    <nav class="{{active}}" >

        <a href="#" class="AddItem"  ng-click="showForm = true">Add Item </a>
        <a href="#" class="DeleteItem">Delete Item</a>
        <a href="#" class="DisplayItem">Display Item</a>
        <a href="#" class="BorrowItem">Borrow Item</a>
        <a href="#" class="ReturnItem">Return Item</a>

    </nav>

        <form ng-show="showForm"ng-submit="submitForm()">
            <h1>Add Items</h1>

            <div layout="column"       layout-align="center center">
                <div> <button class="additmbtn" onclick="">Add Book</button></div>
                <div><button class="additmbtn" onclick="">Add DVD</button></div>
            </div>
        </form>

    </div>

        <script>
            var myApp = angular.module('myApp', []);

            myApp.controller('myCtrl', ['$scope',
                function($scope) {
                    $scope.showForm = false;

                    // init empty user object for our form
                    $scope.user = {};

                    $scope.submitForm = function() {
                        // logic when the form is submitted
                        //...
                    };

                }
            ]);
        </script>




</body>

最佳答案

问题是您在body和div中都多次添加了ng-app。所以Angular JS会抛出一个错误

只需在body或div中添加

<body>

    <div ng-app="myApp" ng-controller="myCtrl">


要么

<body ng-app="myApp">

    <div  ng-controller="myCtrl">

10-08 07:33
查看更多