Im new to ES6,Typscript & Aurelia as my question will show.
I have a small aurelia application and I want to use selectizejs for the tagging function but bind it to a service I have setup within the application.
My viewmodel.ts
attached(){
$('#product_tags').selectize({
delimiter: ',',
persist: false,
load: function(query, callback) {
if (!query.length) return callback();
debugger
this.productService.getProductTags().then(response=>{
callback(response);
});
},
create: function(input) {
return {
value: input,
text: input
}
}
});
}
Within the
load:function(......
How do I gain access to my service this.productService
if I place breakpoint inside of the function, this.
is not my viewmodel but the selectize plugin.
I must be missing something obviously on this but can't figure it out.
Use an es6 arrow function =>
to get the right this
load: (query, callback) => {
if (!query.length) return callback();
debugger
this.productService.getProductTags().then(response=>{
callback(response);
});
},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.