Reputation: 21
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');
}
Upvotes: 1
Views: 176
Reputation: 657118
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;
}
Upvotes: 1