简体   繁体   English

使用angularjs时,旋转木马不起作用?

[英]Carousels don't work when using angularjs?

I have made a responsive image slider using css. 我用css做了一个响应式图像滑块。 I did it by using this example http://bootsnipp.com/snippets/featured/responsive-thumb-preview-in-carousel-indicators . 我是通过使用此示例http://bootsnipp.com/snippets/featured/responsive-thumb-preview-in-carousel-indicators完成的 The sliders work automatically except when I click the carousel, instead of sliding the images, it goes to another page. 滑块自动工作,除非我点击旋转木马,而不是滑动图像,它会转到另一页。 How to stop this? 怎么阻止这个? is it because it is conflicting with angularjs? 是因为它与angularjs相冲突?

Here the code: 这里的代码:

<div id="thumbnail-preview-indicators" class="carousel slide" data-ride="carousel">

    <ol class="carousel-indicators">
        <li data-target="#thumbnail-preview-indicators" data-slide-to="0" class="active">
            <div class="thumbnail">
                <img class="img-responsive" src="../assets/images/abstract_wallpaper_1.png" />
            </div>
        </li>
        <li data-target="#thumbnail-preview-indicators" data-slide-to="1">
            <div class="thumbnail">
                <img class="img-responsive" src="../assets/images/435523.jpg" />
            </div>
        </li>
        <li data-target="#thumbnail-preview-indicators" data-slide-to="2">
            <div class="thumbnail">
                <img class="img-responsive" src="../assets/images/wallpaper-1356336.jpg" />
            </div>
        </li>
    </ol>
    <div class="carousel-inner">
        <div class="item slides active">
            <div class="slide-1"></div>
            <div class="container">
                <div class="carousel-caption">
                    <h1>Hi there! How was your day?</h1>
                    <p>This is the slide 1. Next --></p>
                    <p><a class="btn btn-lg btn-primary" href="#/" role="button">I'm Fine</a></p>
                </div>
            </div>
        </div>
        <div class="item slides">
            <div class="slide-2"></div>
            <div class="container">
                <div class="carousel-caption">
                    <h1>Welcome back! how do you do?</h1>
                    <p>This is slide 2. Moving on... </p>
                    <p><a class="btn btn-lg btn-primary" href="#/" role="button">Great! Thanks.</a></p>
                </div>
            </div>
        </div>
        <div class="item slides">
            <div class="slide-3"></div>
            <div class="container">
                <div class="carousel-caption">
                    <h1>You are back again! Need anything?</h1>
                    <p>This is slide 3. And the last one</p>
                    <p><a class="btn btn-lg btn-primary" href="#/" role="button">Yes peace :)</a></p>
                </div>
            </div>
        </div> 
    </div>
    <a class="left carousel-control" href="#thumbnail-preview-indicators" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
    <a class="right carousel-control" href="#thumbnail-preview-indicators" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>

This is the app.js. 这是app.js.

'use strict'

var app = angular.module('myWeb',
    [
        'ngRoute'
    ]);
console.log('app');
app.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
    $routeProvider
        .when('/',{
            templateUrl: 'home.html',
            controller: 'HomeController'
        });
    $routeProvider
        .when('/signup',{
            templateUrl: 'signup.html',
            controller: 'SignupController'
        });
    $routeProvider
            .when('/contact', {
                templateUrl: 'contact.html',
                controller: 'ContactController'
            });
    $routeProvider
        .when('/about',{
            templateUrl: 'about.html',
            controller: 'aboutController'
        });

    $routeProvider
    .when('/t-and-c-m',
    {
        activatetab: '#t-and-c-m'
    });

}]);

Do i need to configure in angularjs too, to work out this? 我是否还需要配置angularjs,以解决这个问题? Help would be appreciated as i'm a beginner to angularjs. 帮助将不胜感激,因为我是angularjs的初学者。

The css for the question as follows 该问题的CSS如下

#thumbnail-preview-indicators {
  position: relative;
  overflow: hidden;
}
#thumbnail-preview-indicators .slides .slide-1, 
#thumbnail-preview-indicators .slides .slide-2,
#thumbnail-preview-indicators .slides .slide-3 {
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}
    #thumbnail-preview-indicators,
    #thumbnail-preview-indicators .slides,
    #thumbnail-preview-indicators .slides .slide-1, 
    #thumbnail-preview-indicators .slides .slide-2,
    #thumbnail-preview-indicators .slides .slide-3 {
      height: 480px;
    }

#thumbnail-preview-indicators .slides .slide-1{
    background-image: url(../assets/images/abstract_wallpaper_1.png);
}

#thumbnail-preview-indicators .slides .slide-2{
    background-image: url(../assets/images/435523.jpg);
}

#thumbnail-preview-indicators .slides .slide-3{
    background-image:url(../assets/images/wallpaper-1356336.jpg);
}

#thumbnail-preview-indicators .carousel-inner .item .carousel-caption {
  top: 20%;
  bottom: inherit;
}
#thumbnail-preview-indicators .carousel-indicators li,
#thumbnail-preview-indicators .carousel-indicators li.active {
  position: relative;
  width: 100px;
  height: 8px;  
}
#thumbnail-preview-indicators .carousel-indicators li > .thumbnail {
  position: absolute;
  top: 0;
  width: 100px;
  display: none;
  opacity: 0;
  left: 50%;
  margin-top: -80px;
  margin-left: -50px;
}
#thumbnail-preview-indicators .carousel-indicators li:hover > .thumbnail,
#thumbnail-preview-indicators .carousel-indicators li.active > .thumbnail {
  display: block;
  opacity: .8;
}
#thumbnail-preview-indicators .carousel-indicators li.active > .thumbnail:hover{
  opacity: 1;
}
@media screen and (max-width : 480px) {    
    #thumbnail-preview-indicators .carousel-indicators li,
    #thumbnail-preview-indicators .carousel-indicators li.active {
      width: 50px;
      height: 8px;
      position: relative;
    }
    #thumbnail-preview-indicators .carousel-indicators li > .thumbnail {
       width: 50px;
       left: 50%;
       margin-top: -50px;
       margin-left: -25px;
    }
}

Bootstrap Carousel is not compatible with AngularJs due to their use of # within the next/prev buttons. Bootstrap Carousel与AngularJs不兼容,因为他们在next / prev按钮中使用了#。

You can either try to rewrite the bootstrap code for carousel.js or use other projects like this: https://angular-ui.github.io/bootstrap/ 您可以尝试重写carousel.js的引导代码,也可以使用其他项目: https//angular-ui.github.io/bootstrap/

Seems to me you have plenty of <a href='#/'> which will indeed load a new page when they are clicked on. 在我看来,你有足够的<a href='#/'> ,点击它们确实会加载一个新的页面。 What is the intent here ? 这里有什么意图? Most likely, you want to have a ng-click="myfunc()" with a declaration 最有可能的是,你想要一个带声明的ng-click="myfunc()"

$scope.myfunc = function() {....}

to do something else when the user clicks on the link. 在用户点击链接时执行其他操作。 That declaration would be done in the controller for that part of the page (I would create a CarouselController specifically set on the first div with ng-controller="CarouselController , so that you can reuse it in other places if need be). 该声明将在控制器的页面部分来完成(我想创建一个CarouselController上的第一个div专门设置ng-controller="CarouselController ,这样就可以在其他地方重复使用它如果需要的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM