0

Hello I have an angular 2 project which works fine. Now i want to include an external directive from a js i am loading via a script tag i.e. https://test.com/testDirectiveLoad.js this js contains a directive . When i put the script and the directive in the index.html file the directive works. But i want to include the directive in one of my Components for example headerComponent.ts. If i put the directive in that component the browser displays an error:

Template parse errors:
'test' is not a known element:
1. If 'test' is an Angular component, then verify that it is part of this module.
2. If 'test' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. 

Can somebody please help me

Snake
  • 323
  • 1
  • 4
  • 13

2 Answers2

0

if not misunderstanding your question, i think you need to import your external javascript to your component like example below:

declare let createTable: any

then in your export class:

ngOnInit() {
    this.service.getAll().then(() => createTable('#elementName', this.tConfig(), this))
}

tConfig() { ... }

in javascript:

function createTable(elementID, options, delegate) {...}
Kim
  • 980
  • 1
  • 15
  • 29
  • You are creating the component with the ts code but my problem is i only want to use the directive .i.e in the component html file. – Snake Oct 06 '16 at 09:54
0

I resolved it by adding schemas: [ CUSTOM_ELEMENTS_SCHEMA ] to my app.module.ts look at https://stackoverflow.com/a/39517874/6039002 for details

Community
  • 1
  • 1
Snake
  • 323
  • 1
  • 4
  • 13