[英]How to access a javascript function in angular2 template?
I have a javascript(.js) file with set of functions in one object.我有一个 javascript(.js) 文件,在一个对象中包含一组函数。
Now i want to call a function which is (.js) file with (click)event in angular2 template.现在我想在 angular2 模板中调用一个带有 (click) 事件的 (.js) 文件函数。 how to call??
怎么打电话?? IES.js ..........
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');
}
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:您可以将 JS 库中的函数分配给类中的一个字段,然后将
click
事件绑定到该字段:
<button (click)="f()">click me</button>
export class MyComponent {
f = fFromJsLib;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.