AngularJS 使用数组的函数调用
AngularJS function calls using arrays
此 AngularJS 函数的工作方式与我预期的不一样:
app.controller('MainController', ['$scope', 'ForTHEOrder', function($scope, commence) {
commence.success(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
});
commence.failure(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
});
}]);
它应该将一个数组传递给函数调用,其中包含一组对象,然后由嵌套函数调用使用。然而,这似乎并不是实际发生的事情,当我尝试 运行 代码时,我得到了一个错误。如果需要,我可以 post HTML,但我感兴趣的是数组的作用。有人对阵列在这里做什么有什么建议吗?
我目前收到以下错误消息:
Error: $scope.success is not a function
@http://www.orderofthemouse.co.uk/js/controllers/MainController.js:102:3
e@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:36:338
Ce/this.$get</</<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:75:387
H/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:59:19
r@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:7:406
H@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:59:2
g@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:51:299
g@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:51:316
C/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:50:414
rc/d/</<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:17:477
Me/this.$get</k.prototype.$eval@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:125:116
Me/this.$get</k.prototype.$apply@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:125:330
rc/d/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:17:435
e@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:36:338
rc/d@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:17:356
rc@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:18:151
Gd@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:16:463
@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:249:238
a@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:164:4
gf/c@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:32:280
请求的HTML代码如下:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The Order of the Mouse</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/jpg" href="./ico/favicon.jpg">
<meta name="description" content="Psychological horror/detective/spiritual RPG set the medieval, magical future world of 2079; Web-Based">
<meta name="keywords" content="RPG, Horror, Detective, Order of the Mouse, Rabbit-Cat, Dragon-Bear, Clown-Fox, Deer-Wolf">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/style.css">
<script src="./vendor/jquery-1.11.3.min.js"></script>
<script src="./vendor/bootstrap.min.js"></script>
<script src="./vendor/underscore.js"></script>
<script src="./vendor/backbone.min.js"></script>
<script src="./vendor/backbone.marionette.min.js"></script>
<script src="./react/build/react.min.js"></script>
<script src="./react/build/react-dom.min.js"></script>
<script src="http://www.wavepot.com/build.js"></script>
<script src="http://www.wavepot.com/app.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Roboto:500,300,700,200' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet" />
</head>
<body ng-app="myApp">
<div class="header">
<div class="container">
<h1></h1>
</div>
</div>
<div class="main" ng-controller="MainController">
<div class="container">
<h1>{{ title }}</h1>
<h2>{{ placeholder }}</h2>
<div ng-repeat="character in characters" class="col-md-6">
<div class="thumbnail">
<img ng-src="{{ }}">
<p class="name">{{ character.name }}</p>
<p class="name">{{ character.age }}</p>
<p class="url"><a href="http://orderofthemouse.co.uk/">{{ character.url }}</p></a>
<p class="coolness">{{ success.rabbitCat }}</p>
<p class="warmness">{{ failure.rabbitCat }}</p>
<div class="HP">
<p class="Up" ng-click="plusOne($index)"> {{ }} </p>
<p class="Down" ng-click="minusOne($index)"> {{ }} </p>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<h2></h2>
<img style="display: none" src="" width="" />
</div>
</div>
<script>
import sin from '<redacted>';
import { noise } from '<redacted>';
export function dsp(t) {
return (sin(t, 440) + noise()) * 0.1;
}
</script>
<audio controls autoplay>
<source src="DozyOuija.ogg" type="audio/ogg">
<source src="DozyOuija.mp3" type="audio/mp3">
<p>Your User Agent does not support the HTML5 Audio element.</p>
</audio>
<!-- Modules -->
<script src="js/app.js"></script>
<!-- Controllers -->
<script src="js/controllers/MainController.js"></script>
<script>
<!-- Analytics -->
<!-- ANALYTICS REDACTED -->
</script>
</body>
</html>
如果有人需要更多详细信息以帮助他们查明问题的根源,请告诉我。
试试这个:
app.controller('MainController', ['$scope', 'ForTHEOrder', function($scope, commence) {
commence.success(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
$scope.$apply();
});
commence.failure(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
$scope.$apply();
});
}]);
此 AngularJS 函数的工作方式与我预期的不一样:
app.controller('MainController', ['$scope', 'ForTHEOrder', function($scope, commence) {
commence.success(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
});
commence.failure(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
});
}]);
它应该将一个数组传递给函数调用,其中包含一组对象,然后由嵌套函数调用使用。然而,这似乎并不是实际发生的事情,当我尝试 运行 代码时,我得到了一个错误。如果需要,我可以 post HTML,但我感兴趣的是数组的作用。有人对阵列在这里做什么有什么建议吗?
我目前收到以下错误消息:
Error: $scope.success is not a function
@http://www.orderofthemouse.co.uk/js/controllers/MainController.js:102:3
e@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:36:338
Ce/this.$get</</<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:75:387
H/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:59:19
r@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:7:406
H@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:59:2
g@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:51:299
g@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:51:316
C/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:50:414
rc/d/</<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:17:477
Me/this.$get</k.prototype.$eval@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:125:116
Me/this.$get</k.prototype.$apply@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:125:330
rc/d/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:17:435
e@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:36:338
rc/d@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:17:356
rc@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:18:151
Gd@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:16:463
@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:249:238
a@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:164:4
gf/c@http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js:32:280
请求的HTML代码如下:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The Order of the Mouse</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/jpg" href="./ico/favicon.jpg">
<meta name="description" content="Psychological horror/detective/spiritual RPG set the medieval, magical future world of 2079; Web-Based">
<meta name="keywords" content="RPG, Horror, Detective, Order of the Mouse, Rabbit-Cat, Dragon-Bear, Clown-Fox, Deer-Wolf">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/style.css">
<script src="./vendor/jquery-1.11.3.min.js"></script>
<script src="./vendor/bootstrap.min.js"></script>
<script src="./vendor/underscore.js"></script>
<script src="./vendor/backbone.min.js"></script>
<script src="./vendor/backbone.marionette.min.js"></script>
<script src="./react/build/react.min.js"></script>
<script src="./react/build/react-dom.min.js"></script>
<script src="http://www.wavepot.com/build.js"></script>
<script src="http://www.wavepot.com/app.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Roboto:500,300,700,200' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet" />
</head>
<body ng-app="myApp">
<div class="header">
<div class="container">
<h1></h1>
</div>
</div>
<div class="main" ng-controller="MainController">
<div class="container">
<h1>{{ title }}</h1>
<h2>{{ placeholder }}</h2>
<div ng-repeat="character in characters" class="col-md-6">
<div class="thumbnail">
<img ng-src="{{ }}">
<p class="name">{{ character.name }}</p>
<p class="name">{{ character.age }}</p>
<p class="url"><a href="http://orderofthemouse.co.uk/">{{ character.url }}</p></a>
<p class="coolness">{{ success.rabbitCat }}</p>
<p class="warmness">{{ failure.rabbitCat }}</p>
<div class="HP">
<p class="Up" ng-click="plusOne($index)"> {{ }} </p>
<p class="Down" ng-click="minusOne($index)"> {{ }} </p>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<h2></h2>
<img style="display: none" src="" width="" />
</div>
</div>
<script>
import sin from '<redacted>';
import { noise } from '<redacted>';
export function dsp(t) {
return (sin(t, 440) + noise()) * 0.1;
}
</script>
<audio controls autoplay>
<source src="DozyOuija.ogg" type="audio/ogg">
<source src="DozyOuija.mp3" type="audio/mp3">
<p>Your User Agent does not support the HTML5 Audio element.</p>
</audio>
<!-- Modules -->
<script src="js/app.js"></script>
<!-- Controllers -->
<script src="js/controllers/MainController.js"></script>
<script>
<!-- Analytics -->
<!-- ANALYTICS REDACTED -->
</script>
</body>
</html>
如果有人需要更多详细信息以帮助他们查明问题的根源,请告诉我。
试试这个:
app.controller('MainController', ['$scope', 'ForTHEOrder', function($scope, commence) {
commence.success(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
$scope.$apply();
});
commence.failure(function(boolean) {
$scope.rabbitCat = boolean;
$scope.clownFox = boolean;
$scope.mongolFaun = boolean;
$scope.deerWolf = boolean;
$scope.stoatFire = boolean;
$scope.bearDragon = boolean;
$scope.deadWeasel = boolean;
$scope.n_nUrsulafox = boolean;
$scope.$apply();
});
}]);