Ran across this is a google search, but the correct way to pass variables
for use in a function like ngHold would be like so (@see ngEventDirs in
angularjs source for another example):
directive('ngHold', ['$timeout', '$parse', function($timeout, $parse) {
return {
restrict: 'A',
link: function(scope, el, attrs) {
var fn = $parse( attrs.ngHold ),
isHolding, timeoutId
el.on('mousedown', function($event) {
isHolding = true;
timeoutId = $timeout(function() {
if( isHolding ) {
fn( scope, {$event: $event} );
}
}, 500);
});
el.on('mouseup', function() {
isHolding = false;
if(timeoutId) {
$timeout.cancel(timeoutId);
timeoutId = null;
}
});
}
}
}]);
On Friday, January 18, 2013 4:32:32 AM UTC-8, Yermakovich Siarhei wrote:
>
> I guess this is aimed at the AngularUI project mailing list?
>
>
> Maybe you are right. I'm not sure, because both *angular *and *angular-ui
> *projects contain directives.
>
> It would be easier to "get" what this directive does if you specify a
>> scenario where it is used.
>> I could understand what it is doing by reading the code, but it would be
>> much easier if you specified it in text :) .
>
>
> General scenario: we need to perform some action after user presses mouse
> button and holds it for *n* ms. General purpose for this directive is to
> extend available set of gestures. This gesture is commonly used in mobile
> apps.
>
> In my particular scenario (geolocation app), I need to create markers on
> map. With *ngHold *directive my code looks something like this:
> <div class="map" ng-hold="setMarker($event)">
>
> Without *ngHold *directive I would need to subscribe to both
> *ngMousedown *and *ngMouseup *and expose view-related logic to controller.
>
> Also, why are you adding this line ?
>> scope.$event = $event;
>> It doesnt seem to be serving any purpose...
>
>
> Thank you for pointing on it :). I've added this hack in order to be able
> to use expressions like this: ng-hold="setMarker($event)". I'm pretty
> sure there is more correct way exist to accomplish this. This is just
> initial version of the directive and some work still need to be done. I'm
> planning to make a more detailed look at the keypress
> <https://github.com/angular-ui/angular-ui/blob/master/modules/directives/keypress/keypress.js>directive
>
> and use it as a reference implementation.
>
>>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.