gpt4 book ai didi

javascript - 使用数组调用 AngularJS 函数

转载 作者:行者123 更新时间:2023-12-03 08:28:19 25 4
gpt4 key购买 nike

这个 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;
});
}]);

它应该将一个数组传递到函数调用中,其中包含一组对象,然后由嵌套函数调用使用这些对象。然而,这似乎并不是实际发生的情况,当我尝试运行代码时出现错误。如果需要的话我可以发布 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();
});
}]);

关于javascript - 使用数组调用 AngularJS 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33450441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com