Skip to content

Commit

Permalink
feat(package): added matLinkPreview directive to find and render links
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyNahas committed Jul 31, 2018
1 parent 98a2c53 commit 0014c5b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/module/directives/mat-link-preview.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { MatLinkPreviewDirective } from './mat-link-preview.directive';

describe('MatLinkPreviewDirective', () => {
it('should create an instance', () => {
const directive = new MatLinkPreviewDirective();
expect(directive).toBeTruthy();
});
});
36 changes: 36 additions & 0 deletions src/module/directives/mat-link-preview.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {Directive, OnInit} from '@angular/core';
import {fromEvent} from 'rxjs';
import {debounceTime, distinctUntilChanged, map} from 'rxjs/operators';
import {Link, NgxLinkifyjsService} from 'ngx-linkifyjs';
import {LinkPreviewService} from '../..';

@Directive({
selector: '[matLinkPreview]'
})
export class MatLinkPreviewDirective implements OnInit {

constructor(public linkifyService: NgxLinkifyjsService,
public linkPreviewService: LinkPreviewService) {
}

ngOnInit(): void {
this._init();
}

private _init() {
fromEvent(document, 'input')
.pipe(
debounceTime(2000),
distinctUntilChanged(),
map(event => {
const data = event.target['value'];
const links: Link[] = this.linkifyService.find(data);
console.log('data: ', data);
console.log('links: ', links);
return links;
})).subscribe((links) => {
this.linkPreviewService.onLinkFound.emit(links);
});
}

}

0 comments on commit 0014c5b

Please sign in to comment.