I'm using Angular-UI's carousel and I need to tell my google charts to redraw after they have slid into view. In spite of what I've read, I can't seem to hook into the event.
See my attempt: http://plnkr.co/edit/Dt0wdzeimBcDlOONRiJJ?p=preview
HTML:
<carousel id="myC" interval="myInterval">
<slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.image}}" style="margin:auto;">
<div class="carousel-caption">
<h4>Slide {{$index}}</h4>
<p>{{slide.text}}</p>
</div>
</slide>
</carousel>
On document load:
$('#myC').live('slid.bs.carousel', function (event) { console.log("slid"); } );
It should work something like this: http://jsfiddle.net/9fwuq/ - non-angular-ui carousel
Perhaps there is a more Angular way to hook into the fact that my chart has slid into view?
AngularUI Bootstrap has changed naming conventions for controllers as thery have prefixed all of their controllers with prefix
uib
, so below is the updated solution of the original solution provided byrunTarm
:Angular:
Angular with TypeScript:
Thanks,
I managed to modify runTarm's answer so that it calls the callback once the slide has finished sliding into view (i.e. the sliding animation has finished). Here's my code:
The secret lies in using $animate's event handler to call our function once the animation is finished.
There are 3 ways I can think of and that depends of your requirement.
Please see http://plnkr.co/edit/FnI8ZX4UQYS9mDUlrf6o?p=preview for examples.
use $scope.$watch for an individual slide to check if it is become active.
use $scope.$watch with custom function to find an active slide.
use a custom directive to intercept select() function of the carousel directive.
and use it like this:
and in html template:
Hope this help : )
And if you just want to start playing a video when the slide comes into view, and pause when it leaves:
JS
NOTE: Has additional bits for Django
HTML:
Following the answer given by runTarm If you want to know the index of the next slide, you should add something like this:
Then, in the controller you just need to do this to catch the new index:
here's an alternate method that uses controllers, somewhere between runTarm's #2 and #3.
original HTML + a new div:
the custom controller: