I have a programming issue. I have an app where every page presents somehow a list of students.
The page where the students are defined looks like this:
@Component({
selector: 'page-students',
templateUrl: 'students.html'
})
export class StudentsPage {
studentNames: Array<{ id: string, inClass: string, name: string }>;
constructor(public navCtrl: NavController, public uuid: IDGenerator, public popoverCtrl: PopoverController/*public storage: Storage*/) {
// in the end, this can be done by a new class Student / StudentList and JSON Stringify
this.studentNames = [];
}
public addStudent(event) {
this.studentNames.push({ id: this.uuid.generate(), inClass: '8c', name: 'My Name' });
}
public changeStudent(name: string, arrayIndex: number) {
let id = this.studentNames[arrayIndex].id;
}
public removeStudent(event, arrayIndex: number) {
let id = this.studentNames[arrayIndex].id
this.studentNames.splice(arrayIndex, 1);
}
public presentPopover(myEvent, studentName, index) {
let popover = this.popoverCtrl.create(PopoverStudents, { studentName, index });
popover.present({
ev: myEvent
});
/*popover.onDidDismiss((popoverData) => {
let selectedStudent = popoverData;
let selectedIndex = 1;
this.changeStudent(selectedStudent.name, selectedIndex)
})*/
}
}
On every page I define a list studentNames
which I will load from the sqlite database (to be done).
Is this good style or would it be better to define a studentList list and parse this then in this class to the database if something is changed?
If that is so, how can I provide the same class to all pages? Thanks for help!