2

Could someone build me an example ui.bootstrap carousel that has a manual button for sliding, and include two divs of content? I cannot seem to figure out how to use carousels from just their example.

So far all that I have is the following. (showing just the controller and .html for cleanliness)

Controller

app.controller('RegisterController', function ($scope, $http, $location) {
    $scope.cancel = function () {
        $location.path('/');
    };

        $scope.myInterval = 5000; // I don't want timed-sliding. Only manual
        var slides = $scope.slides = [];
        $scope.addSlide = function () {
            slides.push({

            });
        };
        for (var i = 0; i < 4; i++) {
            $scope.addSlide();
        }

});

Registration.html

<div>
    <carousel interval="myInterval">
        <slide ng-repeat="slide in slides" active="slide.active">
            <div>{{slide.content}}</div>
        </slide>
        <button>Next</button>
    </carousel>
</div>

If someone could show me a basic example which includes the two following divs that'd be awesome!

slide 1

<div>
   Name: <input type="text" />
</div>

slide 2

<div>
   Password <input type="password" />
</div>

2 Answers 2

2

Depending on what you are actually trying to achieve, the carousel might not be suitable for your requirement. In that case, like @donnanicolas has said, it would be better to roll your own implementation.

But regardless of whether it is suitable for your requirement or not, here is a super basic example that you have asked for:

<carousel interval="-1">
  <slide active="activeState[0]">
    <div>
      Name: <input type="text" />
    </div>
  </slide>
  <slide active="activeState[1]">
    <div>
      Password: <input type="password" />
    </div>
  </slide>
</carousel>
<button class="btn btn-default" ng-click="nextSlide()">Next</button>

and in the controller:

$scope.activeState = [true, false];

$scope.nextSlide = function () {
  var activeIndex = $scope.activeState.indexOf(true);
  if (activeIndex >= $scope.activeState.length - 1) {
    return; // already reached the last slide
  }

  $scope.activeState[activeIndex] = false;
  $scope.activeState[activeIndex + 1] = true;
};

Example Plunker: http://plnkr.co/edit/44TMU4I9Di3vQKjkexBf?p=preview

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Yea I am also not sure if I shall implement it just yet, but this is very helpful regardless. Thank you!
1

I wouldn't recommend using angular ui bootstrap for this, their carousel is a directive, it should have NO relation with a controller. You should make your own code. You could take a look at their code to see how the calculate sizes and all of that.

EDIT As is says in the comments there are no event in angular ui bootstrap.

1 Comment

FYI, unlike the original from bootstrap, there is no events in the ui-bootstrap's carousel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.