我使用MaterializeCSS's autocomplete與Angular2-Materialize,我試圖將選定的值推入一個數組。不過,我發現了以下錯誤:推入數組不工作的jQuery功能內
Cannot read property 'push' of undefined
這裏是我的組件:
public items: any[] = [];
addItem() {
$('.autocomplete-content').on('click', 'li', function() {
let value = $(this).text().trim();
this.items.push({ [value]: true });
});
}
如果我嘗試push
的jQuery
功能以外的一些隨意的事情,它的工作原理。
這裏是我的HTML:
<input type="text" (change)="addItem()" materialize="autocomplete" [materializeParams]="[{'data': myData | async}]">
是JavaScript的?我承認我沒有及時更新我的ES6 – thedarklord47
它是帶有Typescript的Angular2。 – brians69
可能想標記它的打字稿,然後 – thedarklord47