我正在使用 boostrap-select带有 jquery 的 Angular 2 形式的下拉列表。 Onchange jquery 事件我想调用 Typescript onDropDownChangeChange 方法。但它不起作用。
import { Component, OnInit, ViewChild } from '@angular/core';
import { RequestOptions } from '@angular/http';
import 'rxjs/add/observable/throw';
declare var $: JQueryStatic;
export class TestComponent implements OnInit {
selectedValue: string;
ngOnInit(): void {
$(function() {
var self = this;
$('.selectpicker').on('change', function(){
var selectedds = $(this).find('option:selected').val();
self.onDropDownChangeChange(selectedds); //This is not working
//this.onChange();
});
});
}
onDropDownChangeChange(value: string) {
this.selectedValue = value;
this.PopulateGrid(selectedValue);
}
}
最佳答案
您混淆了范围。应该是这样的:
ngOnInit(): void {
var self = this;
$(function() {
$('.selectpicker').on('change', function(){
var selectedds = $(this).find('option:selected').val();
self.onDropDownChangeChange(selectedds); //This is not working
//this.onChange();
});
});
}
关于angular - 从 Angular 2 中的 jquery 调用 TypeScript 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43869646/