我对 angularjs 有疑问。当我尝试从我的数据库中获取元素时,一切都很好。但是现在,我添加了一个 Controller ,我用它来做一个名为 hb2Controller 的post,它给了我这个错误:
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");
});
关于javascript - 无法使用 Angular 原因 ng-controller 发布帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26992931/