Im using boostrap-select Dropdown in angular 2 forms with jquery. Onchange jquery event i want to call a Typescript onDropDownChangeChange method. But its not working.
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);
}
}
You are confusing the scopes. It should be like this:
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();
});
});
}