javascript - 无法使用 Angular 原因 ng-controller 发布帖子

标签 javascript angularjs angularjs-ng-click

我对 angularjs 有疑问。当我尝试从我的数据库中获取元素时,一切都很好。但是现在,我添加了一个 Controller ,我用它来做一个名为 hb2Controllerpost,它给了我这个错误:

Error: error:areq Bad Argument Argument 'hb2Controller' is not a function, got undefined

我做错了什么?为什么会给我这个错误?

<!DOCTYPE html>
      <html ng-app>
        <head>
          <meta charset="utf-8">
          <meta http-equiv="X-UA-Compatible" content="IE=edge">
          <meta name="viewport" content="width=device-width, initial-scale=1">
          <title>hEY bOss</title>

          <!-- Bootstrap -->
          <link href="css/bootstrap.min.css" rel="stylesheet">

          <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
          <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
          <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
            <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
          <![endif]-->
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
        </head>
        <body>
      <h2 align="center"><small><b>HeyBossTeam</b> TABELLA TEMPI</small></h2>

      <form name="AddTimez" method="POST">
      <div class="table-responsive" ng-controller="hb2Controller">
      <table class="table">
        <thead>
          <tr>
            <th>Gioco</th>
            <th>Pista</th>
            <th>Nome</th>
            <th>Tempi</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><input type="text" ng-model="newTime.Gioco" name="Gioco"></td>
            <td><input type="text" ng-model="newTime.Pista" name="Pista"></td>
            <td><input type="text" ng-model="newTime.Nome" name="Nome"></td>
            <td><input type="text" ng-model="newTime.Tempi" name="Tempi"></td>
          </tr>
          <tr>
            <td colspan="4" align="center">
              <button data-ng-click="addNewTime()" name="add">Aggiungi Tempo</button>
            </td>
          </tr>
        </tbody>
      </table>
      </div>
      </form>

      <div class="table-responsive" ng-controller="hbController">
      <table class="table">
        <thead>
          <tr>
            <th>Gioco</th>
            <th>Pista</th>
            <th>Nome</th>
            <th>Tempi</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="x in datas | orderBy: 'Gioco'">
            <td>{{x.Gioco}}</td>
            <td>{{x.Pista}}</td>
            <td>{{x.Nome}}</td>
            <td>{{x.Tempi}}</td>
          </tr>
        </tbody>
      </table>
      </div>
      <script>
      function hbController($scope,$http) {
          var site = "http://heyboss.altervista.org";
          var page = "/mysqlLulz.php";
          $http.get(site + page).success(function(response) {$scope.datas = response;});
      }
      function hb2Controller($scope,$http) {
            $scope.addNewTime = function(add){
              $http.post("mysqlLulz2.php",{'Gioco': $scope.newTime.Gioco, 'Pista': $scope.newTime.Pista, 'Nome': $scope.newTime.Nome, 'Tempi': $scope.newTime.Tempi})
              .success(function(data, status, headers, config){
                  console.log("inserted Successfully");
              };
            };
          }
      </script>
          <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
          <!-- Include all compiled plugins (below), or include individual files as needed -->
          <script src="js/bootstrap.min.js"></script>
        </body>
      </html>

谢谢!

最佳答案

你错过了一个):

          $http.post("mysqlLulz2.php",{'Gioco': $scope.newTime.Gioco, 'Pista': $scope.newTime.Pista, 'Nome': $scope.newTime.Nome, 'Tempi': $scope.newTime.Tempi})
          .success(function(data, status, headers, config){
              console.log("inserted Successfully");
          });

http://plnkr.co/edit/HkGSvPdQGfDTJbAiYimT?p=info

关于javascript - 无法使用 Angular 原因 ng-controller 发布帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26992931/

相关文章:

JavaScript:如果我使用 position:absolute,SetInterval 不起作用

javascript - AngularJs ng-click 不适用于文件上传字段

javascript - 防止滑动触发 ng-click 处理程序

javascript - 什么是 'matchesSelector' ?

javascript - YouTube API channel 的视频列表

javascript - 尝试在 ES6 中创建 angularJS 指令。尝试双向数据绑定(bind)时出错

javascript - AngularJS - Angular 过滤器按总和行分组

javascript - 类型错误 : Cannot read property 'nombre' of undefined

angularjs - 如何监视使用 ng-bind-html 创建的 ng-model

angularjs - 将ng-click事件插入ng-grid