angularjs - Angular 轮播不起作用

标签 angularjs angular-directive angular-carousel

bower.json 文件的内容:

{
  "name": "blue",
  "version": "0.0.0",
  "dependencies": {
    "angular": "1.3.1",
    "json3": "~3.3.1",
    "es5-shim": "~3.1.0",
    "bootstrap-sass-official": "~3.2.0",
    "angular-sanitize": "1.3.1",
    "angular-animate": "1.3.1",
    "angular-touch": "1.3.1",
    "restangular": "~1.4.0",
    "ui-bootstrap": "~0.11.2",
    "ui-router": "~0.2.11",
    "ng-grid": "~2.0.13",
    "angular-bootstrap": "~0.11.2",
    "angular-carousel": "~0.3.5"
  },
  "devDependencies": {
    "angular-mocks": "1.3.1",
    "angular-scenario": "1.3.1"
  },
  "appPath": "app"
}

View (带中继器和不带中继器):

<div class="attachments col-lg-12">
    <ul rn-carousel class="image">
        <li ng-repeat="image in email.value.files">
            <div class="layer">{{ image }}</div>
        </li>
    </ul>
    <ul rn-carousel class="image">
        <li>slide #1</li>
        <li>slide #2</li>
        <li>slide #3</li>
    </ul>
</div>

email.value.files:

["http://localhost:1337/files/105/Protein_5.png","http://localhost:1337/files/105/Protein_4.png","http://localhost:1337/files/105/Protein_3.png","http://localhost:1337/files/105/Protein_2.png"]

控制台没有错误,存在 css 文件,使用检查元素时指令的根元素为 0px-0px。

最佳答案

我试过下面的代码,它成功了。

<!DOCTYPE html>
<html ng-app>
<head>
    <title>ng Crousal</title>
   <style type="text/css">
        #slides_control > div{
        height: 200px;
    }
    img{
        margin:auto;
        width: 400px;
    }
    #slides_control {
        position:absolute;
        width: 400px;
        left:50%;
        top:20px;
       margin-left:-200px;
    }
  </style>
</head>
<body>
<div ng-app="app">
  <div ng-controller="CarouselDemoCtrl" id="slides_control">
    <div>
      <carousel interval="myInterval">
        <slide ng-repeat="slide in slides" active="slide.active">
          <img ng-src="{{slide.image}}">
          <div class="carousel-caption">
            <h4>Slide {{$index+1}} : #</h4>
          </div>
        </slide>
      </carousel>
    </div>
  </div>
</div>  
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.10.0/ui-bootstrap-tpls.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script>
        angular.module('app', ['ui.bootstrap']);
        function CarouselDemoCtrl($scope) {
            $scope.myInterval = 3000;
            $scope.slides = [
            {
                image: 'http://lorempixel.com/400/200/'
            },
            {
                image: 'http://lorempixel.com/400/200/food'
            },
            {
                image: 'http://lorempixel.com/400/200/sports'
            },
            {
                image: 'http://lorempixel.com/400/200/people'
            }
             
          ];
        }
     
</script>
</body>
</html>

关于angularjs - Angular 轮播不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26731697/

相关文章:

javascript - NVD3 Angular 指令回调触发得太早

android - 如何在本地构建从 .git 存储库获取的 ionic 应用程序

javascript - Angularjs:显示字符串中的最后四个字符并将剩余的字符替换为 'X'

javascript - 使用 $attrs 评估其中带有花括号的属性

javascript - Angular-carousel 不显示/不工作

javascript - AngularJS 1.x 在 ng-repeat 中一次显示一项,单击下一步应显示下一项,依此类推

javascript - AngularJS——如何在 Jasmine 中为输入事件指令编写单元测试

javascript - 具有不同对象属性的表的自定义指令

javascript - Angular Carousel - <li> 元素是否需要 "position: absolute"?