Reputation: 99
I have already used Kendo UI with jQuery in the past but now that I'm using it with Angular 2 there are few things I'm missing. Can we get kendo objects in Angular 2 the same way we were doing in jQuery, using an id selector?
var obj = $('#IdName').data("kendoDropDownList");
var data = obj .dataItem();
var dataSource = $('#IdName').data("kendoGrid").dataSource;
etc...
If it is possible then can you explain me how? If it's not possible then how will I be able to get reference to dataSource, Kendo object, selected value, filter, etc...?
Upvotes: 1
Views: 2053
Reputation: 3149
In your components TypeScript class try this:
export class ExampleComponent implements OnInit {
@ViewChild('myElement') elRef: ElementRef;
constructor() {
}
ngOnInit() {
const nativeElement = this.elRef.nativeElement;
const data = nativeElement.data("kendoGrid").dataSource;
console.log(data);
}
}
And an html example:
<any-html-element #myElement></any-html-element>
Note the @ViewChild. With ViewChild you get a reference to a html element. With .nativeElement you get the actual HTML Element like you would do it in jQuery. Just pass in the ID (in HTML prefixed with hash (#))
Upvotes: 2