1

I have a javascript(.js) file with set of functions in one object.

Now i want to call a function which is (.js) file with (click)event in angular2 template. how to call?? IES.js ..........

var IES = IES|| {};

    IES.execute = function (functionName, args) {
  if(arguments.length>2){
      args = [].slice.call(arguments).splice(1);
  }
  var context = IES;
  var namespaces = functionName.split(".");
  var func = namespaces.pop();
  for(var i = 0; i < namespaces.length; i++) {
    context = context[namespaces[i]];
  }
  return context[func].apply(context, args);
}

  IES.do =  function(){
        console.log('In Do function');
    }
    IES.test = function(){
       console.log('In test function');
    }
    IES.test.hello = function(){
      console.log('In hello function');
    }
2
  • 3
    Please add some code that demonstrates what you have tried and what you want to achieve Commented Jan 20, 2017 at 6:19
  • Make you object exportable and then import it to your component class. Wrap your logic (with your functions) into the function e.g. Func1 and bind it to (click)="Func1()" Commented Jan 20, 2017 at 6:26

1 Answer 1

1

Expressions in bindings can only access members of the components class instance. You can assign the function from your JS library to a field in your class and then bind the click event to that field:

<button (click)="f()">click me</button>
export class MyComponent {
  f = fFromJsLib;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.