I am a beginner with combining jQuery, Knockout and Typescript. Trying to understand why data-bind doesn't work when I try to append some code in AJAX call.
My HTML:
<div class="container">
</div>
My Typescript class (ViewModel):
export class ViewModel {
name = ko.observable('NAME PROPERTY');
constructor() {
$('.container').append('<h6 data-bind="text: name"></h6>');
this.getDataAjax();
}
public getDataAjax() {
var self = this;
$.ajax({
type: "GET",
url: "http://localhost:4000/GetData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('.container').append('<h6 data-bind="text: name"></h6>');
console.log(data);
}
});
}
}
Appending header with name property in constructor works fine and I can see data. However, when I append it after returning data it doesn't show at all. AJAX call works fine - cause I can see proper data in console log.
I'm working on dynamic form and need to append some HTML after ajax call. I would appreciate your help, hints, any explanation ;-) Cheers