【发布时间】:2017-10-07 18:06:42
【问题描述】:
我正在使用带有 jquery 的 Angular 2 形式的 boostrap-select Dropdown。 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);
}
}
【问题讨论】:
-
在您仍然可以使用 ngModel 和/或模板语法来实现这一点的同时,使用 jQuery 监听该事件有什么意义?
-
一般规则 - 每次你想在 Angular/React/Vue 应用程序中使用 jQuery 时,都有 99.999% 的机会有更好的做事方式。
标签: angular typescript angular2-forms typescript2.0