mtr / angular-iscroll

AngularJS module that enables iScroll 5 functionality, wrapping it in an easy-to-use directive.
MIT License
74 stars 27 forks source link

How to use events with angular? #33

Closed MartyBolton closed 8 years ago

MartyBolton commented 8 years ago

Can you show me a small example of hooking in to the onScrollEnd event using angular? I see the javascript examples but I'm using you example. I'm missing something basic. I was hoping to specify in html using iscroll={options} or $scope.instance.on('event') but that does not seem to be the right approach.

Update: I was able to hook into it with the global configuration option. I'm wondering if I can access it from my instance directly or would you recommend I broadcast an event from my configuration. Ultimately - trying to implement an easy to use PullDownRefresh() for mobile anywhere I need it.

thanks - awesome wrapper!

<div class="iscroll-wrapper" iscroll iscroll-instance="instance"
        <div class="iscroll-scroller">

```   .
DarthBender commented 8 years ago

So, maybe this can help you. I think iscroll={options} is the best place for event handlers.

Js:

app.controller('MainCtrl', function () {
    this.PullDownRefresh = function () {};
});

Html:

<div ng-controller="MainCtrl as vm">
   <div class="iscroll-wrapper" iscroll="{ onScrollEnd: vm.PullDownRefresh}"
        <div class="iscroll-scroller">
</div>
MartyBolton commented 8 years ago

Thanks! I did get it to work in configuration, but I wanted to use it as you posted local to controller thanks again!

mtr commented 8 years ago

Thank you so much for handling this issue, @DarthBender.