该按钮不起作用。
我点击按钮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>
答案 0 :(得分:0)
您的应用名称错误。
<body ng-app="myapp">
否则,angular会给出喷油器模块错误。您应该始终打开控制台并查看错误以便更好地理解
答案 1 :(得分:0)
你有错误@ 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>