mihnsen / ui-carousel

A simple, lightweight module for carousel in your AngularJS app, Inspired from slick carousel.
http://mihnsen.github.io/ui-carousel/
MIT License
77 stars 67 forks source link

how to access controller scope in <carousel item> tag #34

Closed Assdi closed 6 years ago

Assdi commented 6 years ago

e.g `<ui-carousel slides="vm.independentQuizes" slides-to-show="4" slides-to-scroll="4" on-init="vm.onCarouselInit()" on-before-change="vm.before()" on-after-change="vm.yo(currentSlide)">

Quiz {{vm.as}}

{{item.Name}}

` I want to access vm.as in item tag
ccasad commented 6 years ago

Same here. Is this not supported?

Assdi commented 6 years ago

quick solution is to push the controller object in slides object

mcelligottnick commented 6 years ago

I nicer option is to add another directive scope prop, and pass your scope into there. In https://github.com/mihnsen/ui-carousel/blob/master/src/ui-carousel/directives/carousel.directive.js where it defines the scope, add another key like scope: '='.

Then when using the directive pass in your scope (or any other object your want, really);

<ui-carousel ... scope='$scope'>

Then inside the item you can use it as ctrl.scope.yourScopeProp.

martinmanzo commented 6 years ago

@Assdi how can I do that?

Assdi commented 6 years ago

e.g if u have obj vm.solution (in controller) and u want to access it in carousel html then u can push the vm.solution into carousel object. In above case I have pushed into slides="vm.independentQuizes"

martinmanzo commented 6 years ago

Yeah I was doing that but needed to access a function in my controller from the crousel-item to display some info and could do that. I ended up preprocessing the items to show in order to load the info to the objects as a property.

Anyway, thanks for your time to respond!!

Assdi commented 6 years ago

now i stuck in problem I have to call controller function here :( @martinmanzo

Assdi commented 6 years ago

yahoo Ive done that :+1:

illuska812 commented 6 years ago

How?

Assdi commented 6 years ago

same solution :D push the function reference into slide obj . just i did above for controller scope @illuska812 $scope.myFunction=function(){console.log('hi')} and push this function ref into slide obj like this vm.slides.myfunc=myFunction