2016-05-29 57 views
-1

該按鈕不起作用。只需單擊無響應的按鈕

我點擊了按鈕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

作爲開發者,你必須始終保持你的_Developer工具_開發而開發.. – Rayon

+0

更改應用程序名稱爲myapp –

+0

你也在'ng-controller'中輸入錯誤 –

回答

0

您的應用程序名稱有誤。

<body ng-app="myapp"> 

否則,角度會導致注射器模塊錯誤。你應該總是打開控制檯,並看到了錯誤,更好地瞭解

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>