[英]ng-click the button with no response
The button is not work.按钮不起作用。
I click the button ng-click="goSearchTitle()"
and it has no response.我单击按钮
ng-click="goSearchTitle()"
并且没有响应。
Why it doesn't work?为什么它不起作用?
<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>
Your app name is wrong.您的应用名称有误。
<body ng-app="myapp">
Otherwise, angular will give an injector module error.否则,angular 会给出一个注入器模块错误。 You should always open console and see the errors to understand better
您应该始终打开控制台并查看错误以更好地理解
You have typo @ ng-contoller
, it is ng-controller
你有错字 @
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.