We have an existing plugin that we call like this
var result = $('.myElement').OurPluginName({});
I am trying to replace this with a Angular2 Directive.
My test.ts:
/// <reference path="test.d.ts" />
import { Directive, ElementRef, NgZone } from '@angular/core';
@Directive({
selector: 'test'
})
export class Test {
public ngAfterViewInit(): void {
this.zone.runOutsideAngular(() => {
this.OurPluginName({});
});
}
}
My test.d.ts:
declare function OurPluginName(options: Object): void;
Despite creating a declaration, it still is giving me an error:
Property 'OurPluginName' does not exist on type 'Test'.
SOLUTION: (thanks to Volodymyr Bilyachat)
test.ts:
/// <reference path="test.d.ts" />
import { Directive, ElementRef, NgZone } from '@angular/core';
@Directive({
selector: 'test'
})
export class Test {
public constructor(private elRef: ElementRef) {
}
public ngAfterViewInit(): void {
this.zone.runOutsideAngular(() => {
$(this.elRef.nativeElement).OurPluginName({});
});
}
}
test.d.ts:
declare var $: any;