我想將此查詢的jQuery(this).closest('li').attr('id')
的結果存儲到Angular 2 Typescript的變量中。如何將從jquery訪問的元素id存儲到Angular 2 Typescript的變量
export class DashboardComponent implements OnInit {
angVariable: any;
ngOnInit() {
jQuery(this.elRef.nativeElement).on("click", "li a", function() {
/* I want to store this query result to Angular typescript
variable say angVariable and query is
"jQuery(this).closest('li').attr('id');"
basically I want to store Id of clicked li a into
angular 2 typescript variable angVariable
*/
});
}
somefunction() { // I will use angVariable here
}
}
進入這裏
碼我怎樣才能做到這一點?
有沒有什麼辦法讓我可以基於jquery中的條件滿足將打字稿變量設置爲true或false。 –