Answer the question
In order to leave comments, you need to log in
How to make automatic increment by 1?
When adding new data, I always have 0 displayed at the beginning of the ID, but how to make it take a number from the database and add +1 to each new entry:
sprBitType.ts:
<code>export class SprBitType{
constructor(
public bit_type_id: number,
public name: string,
public is_active: boolean,
public rn: number) { }
}</code>
...
sprBitTypes: Array<SprBitType>;
isNewRecord: boolean;
private isOpenForm: boolean = false;
constructor (
private serv: SprBitTypeService,
public toastManager: ToastsManager,
)
{this.sprBitTypes = new Array<SprBitType>();}
...
createPost() {
this.isOpenForm = true;
this.sprBitType = new SprBitType(0,"",false,0);
this.sprBitTypes.unshift(this.sprBitType);
this.isNewRecord = true;
}
...
saveSprBitType() {
this.isOpenForm = false;
if (this.isNewRecord) {
// Добавление запись
this.serv.createSprBitType(this.sprBitType).subscribe(data => {
this.toastManager.success('Данные успешно сохранены!', 'Выполнено'),
this.loadSprBitTypes();
});
this.isNewRecord = false;
this.sprBitType = null;
} else {
// Изменение запись
this.serv.updateSprBitType(this.sprBitType).subscribe(data => {
this.toastManager.success('Данные успешно сохранены!', 'Выполнено'),
this.loadSprBitTypes();
});
this.sprBitType = null;
}
}
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question