Я следовал тому же учебнику и получил ту же проблему.Проблема в том, что что-то очень интересное и мощное называется Зоны .
Идея состоит в том, что вам нужно сообщить Angular, что массив с примечаниями имеетизменилось, сделав что-то вроде этого:
// Angular
import { Component, NgZone } from '@angular/core';
// Ionic
import { NavController, AlertController } from '@ionic/angular';
// Services
import { NotesService } from '../services/notes.service';
import { AlertOptions } from '@ionic/core';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(
private ngZone: NgZone, // Add this in the constructor
private navCtrl: NavController,
private alertCtrl: AlertController,
private notesService: NotesService,
) { }
ngOnInit() {
this.notesService.load();
}
addNote() {
const alertOptions: AlertOptions = {
header: 'New Note',
message: 'What should the title of this note be?',
inputs: [
{
type: 'text',
name: 'title'
}
],
buttons: [
{
text: 'Cancel'
},
{
text: 'Save',
handler: (data) => {
// Create the note inside a Zone so that Angular knows
// that something has changed and the view should be updated
this.ngZone.run(() => {
this.notesService.createNote(data.title);
});
}
}
]
};
this.alertCtrl
.create(alertOptions)
.then((alert) => {
alert.present();
});
}
}