AngularJS 图像未显示在屏幕上
AngularJS Images Not Displaying on Screen
幻灯片轮播的图像未显示在屏幕上。在元素下的控制台中,我清楚地看到路径:但它们没有显示在屏幕上。
有人可以帮忙吗?我的子文件夹中有图像,当我单击文件夹时,图像路径会正确更改。想不通这一点。谢谢!
index.html
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<script src="example.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="CarouselDemoCtrl">
<div style="height: 305px">
<div uib-carousel active="active" interval="myInterval" no-wrap="noWrapSlides">
<div uib-slide ng-repeat="slide in slides">
<img ng-src="{{uri}}/{{currentFolder}}/{{slide}}" style="margin:auto;">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="navbar navbar-default navbar-fixed-botom" role="navigation">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li ng-repeat="folder in folders" ng-class="{active:activeFolder(folder)}" ng-click="selectFolder(folder)">
<a ng-href="#{{folder}}">{{folder}}</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</div>
</body>
</html>
example.js
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('CarouselDemoCtrl', function ($scope) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var currentIndex = 0;
$scope.uri = "slides";
$scope.folders = ['cats','dogs'];
$scope.slides = ["1.jpg","2.jpg","3.jpg"];
$scope.currentFolder = $scope.folders[0];
$scope.selectFolder = function (folder) {
$scope.currentFolder = folder;
};
$scope.activeFolder = function (folder) {
return (folder === $scope.currentFolder);
};
});
如果路径正在更新并且看起来正确,那么这不太可能是 Angular 问题。我的猜测是指定的路径不正确。
从你的代码中我可以看出你指定了一个相对路径(例如 slides/cats/1.jpg
),但它是相对于当前路径的。因此,如果您当前的路径是 www.mywebpage.com/foo/bar
,它会期望图像位于 www.mywebpage.com/foo/bar/slides/cats/1.jpg
。那是你的头像吗?
如果没有,请尝试这两个选项之一。
- 在路径
/slides/cats/1.jpg
的开头添加一个 /
。这将使浏览器从 www.mywebpage.com/slides/cats/1.jpg
请求图像
- 指定绝对值 URL 以确保它来自正确的位置:
请参阅此处了解如何获取当前 url:
Carousel 缺少用于查找幻灯片的索引。添加一个 id 属性 到您的幻灯片,从 0 开始。这样 bootstrap 可以跳到下一个索引。
将您的 HTML 更改为:
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<script src="example.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="CarouselDemoCtrl">
<div style="height: 305px">
<div uib-carousel active="active" interval="myInterval" no-wrap="noWrapSlides">
<div uib-slide ng-repeat="slide in slides" index="slide.id">
<img ng-src="{{uri}}/{{currentFolder}}/{{slide.image}}" style="margin:auto;">
</img>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="navbar navbar-default navbar-fixed-botom" role="navigation">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li ng-repeat="folder in folders" ng-class="{active:activeFolder(folder)}" ng-click="selectFolder(folder)">
<a ng-href="#{{folder}}">{{folder}}</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</div>
</div>
</body>
</html>
你的 javascript 到:
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('CarouselDemoCtrl', function ($scope) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var currentIndex = 0;
$scope.uri = "slides";
$scope.folders = ['cats','dogs'];
$scope.slides = [{image:"1.jpg", id:0},{image: "2.jpg", id:1},{image:"3.jpg", id:2}];
$scope.currentFolder = $scope.folders[0];
$scope.selectFolder = function (folder) {
$scope.currentFolder = folder;
};
$scope.activeFolder = function (folder) {
return (folder === $scope.currentFolder);
};
});
幻灯片轮播的图像未显示在屏幕上。在元素下的控制台中,我清楚地看到路径:但它们没有显示在屏幕上。 有人可以帮忙吗?我的子文件夹中有图像,当我单击文件夹时,图像路径会正确更改。想不通这一点。谢谢!
index.html
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<script src="example.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="CarouselDemoCtrl">
<div style="height: 305px">
<div uib-carousel active="active" interval="myInterval" no-wrap="noWrapSlides">
<div uib-slide ng-repeat="slide in slides">
<img ng-src="{{uri}}/{{currentFolder}}/{{slide}}" style="margin:auto;">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="navbar navbar-default navbar-fixed-botom" role="navigation">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li ng-repeat="folder in folders" ng-class="{active:activeFolder(folder)}" ng-click="selectFolder(folder)">
<a ng-href="#{{folder}}">{{folder}}</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</div>
</body>
</html>
example.js
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('CarouselDemoCtrl', function ($scope) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var currentIndex = 0;
$scope.uri = "slides";
$scope.folders = ['cats','dogs'];
$scope.slides = ["1.jpg","2.jpg","3.jpg"];
$scope.currentFolder = $scope.folders[0];
$scope.selectFolder = function (folder) {
$scope.currentFolder = folder;
};
$scope.activeFolder = function (folder) {
return (folder === $scope.currentFolder);
};
});
如果路径正在更新并且看起来正确,那么这不太可能是 Angular 问题。我的猜测是指定的路径不正确。
从你的代码中我可以看出你指定了一个相对路径(例如 slides/cats/1.jpg
),但它是相对于当前路径的。因此,如果您当前的路径是 www.mywebpage.com/foo/bar
,它会期望图像位于 www.mywebpage.com/foo/bar/slides/cats/1.jpg
。那是你的头像吗?
如果没有,请尝试这两个选项之一。
- 在路径
/slides/cats/1.jpg
的开头添加一个/
。这将使浏览器从www.mywebpage.com/slides/cats/1.jpg
请求图像
- 指定绝对值 URL 以确保它来自正确的位置:
请参阅此处了解如何获取当前 url:
Carousel 缺少用于查找幻灯片的索引。添加一个 id 属性 到您的幻灯片,从 0 开始。这样 bootstrap 可以跳到下一个索引。
将您的 HTML 更改为:
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<script src="example.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="CarouselDemoCtrl">
<div style="height: 305px">
<div uib-carousel active="active" interval="myInterval" no-wrap="noWrapSlides">
<div uib-slide ng-repeat="slide in slides" index="slide.id">
<img ng-src="{{uri}}/{{currentFolder}}/{{slide.image}}" style="margin:auto;">
</img>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="navbar navbar-default navbar-fixed-botom" role="navigation">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li ng-repeat="folder in folders" ng-class="{active:activeFolder(folder)}" ng-click="selectFolder(folder)">
<a ng-href="#{{folder}}">{{folder}}</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
</div>
</div>
</body>
</html>
你的 javascript 到:
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('CarouselDemoCtrl', function ($scope) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var currentIndex = 0;
$scope.uri = "slides";
$scope.folders = ['cats','dogs'];
$scope.slides = [{image:"1.jpg", id:0},{image: "2.jpg", id:1},{image:"3.jpg", id:2}];
$scope.currentFolder = $scope.folders[0];
$scope.selectFolder = function (folder) {
$scope.currentFolder = folder;
};
$scope.activeFolder = function (folder) {
return (folder === $scope.currentFolder);
};
});