gpt4 book ai didi

javascript - Bootstrap 轮播TypeError : f[0] is undefined

转载 作者:搜寻专家 更新时间:2023-11-01 05:21:35 24 4
gpt4 key购买 nike

我们正在使用 Bootstrap Carousel 并希望加载动态幻灯片(数组中的每个项目都有一张幻灯片)。 AngularJS 用于生成数组并循环遍历。

但是在运行时,我们得到了一个 javascript 错误TypeError: f[0] is undefined 。数组由 $http.get 填充

尝试了来自 https://docs.angularjs.org/ 的替代可能性和 http://w3schools.com

  • 如果不使用 $http.get 在脚本中定义数组,则 Carousel 可以正常工作
  • $http.get 生成的数组在“tr ng-repeat”中正确显示

这是代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Fresh</title>
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">

<div ng-show="names.length">

<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="{{ $index }}"
ng-repeat="x in names"></li>
</ol>

<div class="carousel-inner" role="listbox">
<div class="item" ng-repeat="x in names">{{x.Name}}
{{x.Country}}</div>
</div>

<a class="left carousel-control" href="#myCarousel" role="button"
data-slide="prev"> <span
class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a> <a class="right carousel-control" href="#myCarousel" role="button"
data-slide="next"> <span
class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>

</div>

</div>
</div>

<script>

// window.alert('Inside script');
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
// window.alert( 'Inside controller' );
$scope.names = [];
$http.get("http://www.w3schools.com/angular/customers.php").then(
function(response) {
$scope.names = response.data.records;
window.alert('Inside get');
});

});
</script>
</body>
</html>

最佳答案

从你的 div 中移除 data-ride="carousel"

关于javascript - Bootstrap 轮播TypeError : f[0] is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35671557/

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