【发布时间】:2020-05-19 09:16:16
【问题描述】:
我正在尝试在我的 Angular 2 应用程序上使用这个 convForm jquery 插件。
我已成功将 jquery 和 convForm 安装到我的项目中,编辑 angular.json 文件。
在plugin example中,他们有回调函数,它们的html字段在属性下:data-callback。
我不明白如何在 angular 组件中使用这些回调函数,因为回调不使用打字稿调用函数。
conv-form.html
<div id="chat" class="conv-form-wrapper">
<form action="/" method="post" class="hidden" onsubmit="event.preventDefault()">
<input type="number" data-callback="amount"
data-conv-question="What is the amount you like ?" name="amount"
data-pattern="^[0-9]*$">
</form>
</div>
conv-form.ts
import { Component, OnInit } from '@angular/core';
declare let $: any;
@Component({
selector: 'app-conv-form',
templateUrl: './conv-form.component.html',
styleUrls: ['./conv-form.component.scss']
})
export class ConvFormComponent implements OnInit {
ngOnInit() {
let convForm = $('#chat').convform({ selectInputStyle: 'disable' });
}
amount(stateWrapper, ready) {
if(stateWrapper.current.answer.value.length > 0){
ready();
}
}
}
呈现此问题时,我收到错误消息:
Uncaught TypeError: window[convState.current.input.callback] is not a function
at Object.onInputSubmit
如何像示例一样调用回调函数,但使用角度?
相当于:
<script>
function google(stateWrapper, ready) {
window.open("https://google.com");
ready();
}
</script>
【问题讨论】:
标签: jquery angular jquery-plugins