html - Angular ใช้ฟังก์ชัน javascript
ฉันกำลังสร้างแอปและฉันต้องการใช้ Twit API อย่างไรก็ตามด้วยเหตุผลบางประการฉันไม่สามารถทำให้โค้ดทำงานในไฟล์ TypeScript ได้
ดังนั้นฉันจึงสร้างไฟล์ js ในไดเรกทอรี
และนี่คือโค้ดที่อยู่ใน dashboard.page.js (แน่นอนว่าได้ลบคีย์ออกเพื่อความปลอดภัยแล้ว)
var Twit = require('twit')
var T = new Twit({
consumer_key: '...',
consumer_secret: '...',
access_token: '...',
access_token_secret: '...',
})
//
// tweet 'hello world!'
//
function sendTweet(){
T.post('statuses/update', { status: 'hello CarlLLL' }, function(err, data, response) {
console.log(data)
})
}
และนี่คือโค้ดบางส่วนจาก dashboard.page.html
<ion-row class="ion-justify-content-center">
<ion-col size=" 12">
<div class = "imageBox" (click) ="startCountdown(5)" onclick= 'sendTweet();'>
<!-- <div class = "imageBox" (click) ="shareFacebook()"> -->
<img src="../../assets/help_btn.png" style="width :100%;">
<div class = "imageText">{{imageText}}</div>
</div>
</ion-col>
</ion-row>
และข้อผิดพลาดที่ฉันได้รับคือ
ReferenceError: sendTweet is not defined
ฉันอยากทราบว่าคนสามารถเรียกฟังก์ชันจากไฟล์จาวาสคริปต์ของฉันไปยังหน้า HTML ได้อย่างไร
