0

Hi I have started working on angular2. I came across a scenario where I have to put external javascript file in my angular2 application. I have tried as below. At first I created testjs.js file and I added the below code

function test() {
    alert('TestingFunction')
}

Then in index.html I referenced as below.

 <script src="~/ClientApp/Assets/testjs.js"></script>

Then I have fetchdata.component.js file. I added below code into it.

declare var test: any;
 f() {
        new test();
    }

Finally in fetchdata.component.html I added below code.

<h1>
    <button (click)='f()'>Test</button>
</h1>

When click the button it prompts below error in browser.

FetchDataComponent.html:26 ERROR ReferenceError: test is not defined
    at FetchDataComponent.f (fetchdata.component.ts:15)

Can someone help me in this issue? Any help would be appreciated. Thank you!

Dinuka Dayarathna
  • 169
  • 1
  • 3
  • 9
Giridhar Joshi
  • 93
  • 1
  • 1
  • 10

0 Answers0