以下是一个在Angular前端中保存数据到数组的示例代码:
export class AppComponent {
items: string[] = [];
// 其他相关代码...
}
- {{ item }}
export class AppComponent {
items: string[] = [];
newItem: string;
addItem() {
this.items.push(this.newItem);
this.newItem = ''; // 清空输入框
}
// 其他相关代码...
}
这样,当用户在输入框中输入内容并点击保存按钮时,该内容将被添加到数组中,并在模板中展示出来。