angular - 从 Angular 2 中的 jquery 调用 TypeScript 方法

标签 angular typescript angular2-forms typescript2.0

我正在使用 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/

相关文章:

angular - 使用 typescript 在 Angular 6 中自定义 Ngx-toastr

javascript - 使用 Typescript、类型保护和反射来根据类型验证对象

Angular 2 : how to post+redirect form with action on external site

angular2-forms - Angular2 Forms 禁用具有数据绑定(bind)值的组件中的控件

javascript - Angular 2/4/5/6 - 在其组件类端转换自定义组件的 innerHTML

angularjs - 在 Angular 2 中,当我尝试使用双向绑定(bind)时 ngIF 不起作用

angular - ngBootstraps typeahade 导致错误 : Cannot find a differ supporting object '[object Promise]' of type 'object'

angular - 使用 Angular 进行 Steam 身份验证

javascript - 为什么我不能使用 SystemJS 直接从 node_modules 导入?

node.js - 将 angular2 模块/组件发布为 npm 包