0

In script.js

;(function($, window, undefined) {
  $.fn.myFunction = function() {/*codes*/};
}(jQuery, window));

In index.html

<head>
  ....
  <script src="assets/js/script.js"></script>
</head>

In component.ts

ngAfterViewInit(){
    myFunction();
}

I have error - Cannot find name 'myFunction'

Sasa
  • 205
  • 1
  • 3
  • 16
  • 1
    The function is binded to jQuery, not to the angular component itself. You have to either import or just delcare jQuery in Angular, then use `$.myFunction()` (or `jQuery.myFunction()` according to the import / declaration type). – briosheje Jul 10 '18 at 06:47
  • Check for resolution https://stackoverflow.com/a/39400260/4868839 – User3250 Jul 10 '18 at 06:55
  • @User3250 it might not solve his problem, since it looks like jQuery is included somewhere else as long as he is using it in script.js. We need further informations, since using jQuery with angular (and webpack / angular-cli / systemjs / **whatever, really**) is slightly more complex and the possible solutions are way different according to the chosen approach. Besides, TSD is deprecated since a while. – briosheje Jul 10 '18 at 06:57

0 Answers0