Issue
I know it must be something very simple, but cannot figure it today - Monday :)
so, I have a directive for a responsive table
import {Directive, HostListener} from '@angular/core';
@Directive({
selector: '.table-responsive'
})
export class TableResponsiveDirective {
@HostListener('click', ['$event']) scroll(direction: string, event: MouseEvent){
console.info('clicked: ' + direction + ' ' +event);
event.stopPropagation();
event.preventDefault();
}
}
and this is my view
<div class="table-responsive">
<a href="#" (click)="scroll('left', $event)">LEFT</a>
<a href="#" (click)="scroll('right', $event)">RIGHT</a>
<table>...</table>
</div>
Now, how do I make it work? I don't want to capture the whole .table-responsive... but just those two links
Solution
Don't want to go in depth but this will be a quick solution for you. Try to bind your left, right information with event, bind it inside with event like this
<div class="table-responsive">
<a href="#" (click)="$event.left = true">LEFT</a>
<a href="#" (click)="$event.right = true">RIGHT</a>
<table>...</table>
</div>
extract it like this
import {Directive, HostListener} from '@angular/core';
@Directive({
selector: '.table-responsive'
})
export class TableResponsiveDirective {
@HostListener('click', ['$event'])
scroll($event){
if ($event.left) {
console.info('clicked: ' + $event.left);
} else if ($event.right) {
console.info('clicked: ' + $event.right);
}
event.stopPropagation();
event.preventDefault();
}
}
In this case you can simply know the direction by left, right flags in event object and add your code :)
Answered By - Babar Bilal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.