繁体   English   中英

ng-单击按钮没有响应

[英]ng-click the button with no response

按钮不起作用。

我单击按钮ng-click="goSearchTitle()"并且没有响应。

为什么它不起作用?

    <body ng-app="myapp">

    <div ng-contoller="searchbyTitle">
        <h3>Search by Title</h3>
        <div>
            <input type="text" id="searchTitle" placeholder="Enter a title" ng-model="searchTitle"/>
            <button type="button" id="goSearchTitle" ng-click="goSearchTitle()">Search</button>
        </div>

    </div>

    <script>
        angular.module("myapp", []).controller("searchbyTitle", function($scope, $http) {
            $scope.goSearchTitle = function(){
                alert($scope.searchTitle);
            }
        });
    </script>
    </body>

您的应用名称有误。

<body ng-app="myapp">

否则,angular 会给出一个注入器模块错误。 您应该始终打开控制台并查看错误以更好地理解

你有错字 @ ng-contoller ,它是ng-controller

 var myApp = angular.module("myapp", []); myApp.controller("searchbyTitle", function($scope, $http) { $scope.goSearchTitle = function() { alert($scope.searchTitle); } });
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <body ng-app="myapp"> <div ng-controller="searchbyTitle"> <h3>Search by Title</h3> <div> <input type="text" id="searchTitle" placeholder="Enter a title" ng-model="searchTitle" /> <button type="button" id="goSearchTitle" ng-click="goSearchTitle()">Search</button> </div> </div> </body>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM