I have this situation where on clicking the html element i am fetching value of attribute in home.ts
using jquery. When the button is clicked,I want to call a function and pass this fetched attribute's value in a variable in the called function.
Below is my code:
**home.html**
<div id="mainDiv">
<span action="10004">Quick Task</span>
</div>
**home.ts**
//declare var $: any;
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import $ from "jquery"; //intentional use of jQuery
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
}
actionid;
ngOnInit(){
var mainDiv = document.getElementById("mainDiv");
mainDiv.addEventListener("click", function (event) {
console.log("Inside Event Listener");
event.preventDefault();
var link_id = $(event.target).attr("action");
console.log("Actionid is:: " + link_id);
// this.actionid = link_id;
// var x = this.callpagedata();
});
}
callpagedata(){
console.log("callpagedata function fired,actionid is::", this.actionid)
}
}
Edit
Something like this needs to be used:
this.actionid = HTMLElement.addEventListener<"click">.......
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…