I am using Ionic framework 4 . I want to set a default value in input tag .
here is my code :
in .ts file
constructor( private route: ActivatedRoute,private router: Router, private sqlite: SQLite, private sqliteDbCopy: SqliteDbCopy) {
this.PhNumber = this.route.snapshot.paramMap.get('number');
}
in html:
> <ion-input type="text" [(ngModel)]="ph_number" value={{PhNumber}}></ion-input>
> <ion-button size="small" type="submit" expand="block" (click)="saveChat()">Send Your Message</ion-button>
But don’t know why the value is not displaying in the text field. If I remove the ngModel like :
> <ion-input type="text" value={{PhNumber}} ></ion-input>
> <ion-button size="small" type="submit" expand="block" (click)="saveChat()">Send Your Message</ion-button>
The value is displaying . I am new in Ionic please help . How to display the value with ngModel . without ngModel how can I save data to database.
My save to database function :
msg='';ph_number =''; saveChat(){ var status='Outgoing'; this.sqlite.create({ name: 'chat_app.db', location: 'default' }).then( (db: SQLiteObject) => { db.executeSql('CREATE TABLE IF NOT EXISTS chat_list_details(id INTEGER PRIMARY KEY AUTOINCREMENT,ph_number VARCHAR(32),status VARCHAR(32),msg TEXT)', []) .then(() => console.log('Executed SQL')) .catch(e => console.log(e)); db.executeSql(" INSERT INTO chat_list_details (ph_number,status,msg) VALUES (?,?,?) ", [ this.ph_number,status,this.msg ] ).then(() => console.log('value inserted in SQL')) .catch(e => console.log(e)); }) }