Home > Back-end >  Call with a button a saved number in another page( IONIC, Angular)
Call with a button a saved number in another page( IONIC, Angular)

Time:05-18

Hi I want to call a number which is saved in another page. I don't know how to explain this well but I put some captures, and the code that I'm trying to use, I just only want to catch the value of the number and put into the button to call. I'm using ionic framework and angular. I'm very new at this but I want to create an app and I'm stuck with this. Sorry for my english is not my native language. Client Detail

Call button

Button page .ts

Detail html page(the first image)

button page html (click) function

CodePudding user response:

For that, you can create services and then store your PhoneNumber in services. Check this out https://angular.io/tutorial/toh-pt4 .I hope it will help you.

CodePudding user response:

import { ICompanyAddress } from './../interfaces/Map';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class SharedDataService {
  _phoneNumber: string;
  constructor() { }

  get phoneNumber(): string {
    return this._phoneNumber;
  }
  set phoneNumber(newValue: string) {
    this._phoneNumber = newValue;
  }
}

Now You could change access its data from any page and changing its value:

example1 (change phoneNumber from a page)

  constructor(private sharedDataService : SharedDataService) {
this.changePhoneNumber()

 }

changePhoneNumber(){

this.sharedDataService.phoneNumber = '12345678'

}

example1 (get last phoneNumber changed value in a page)

constructor(private sharedDataService : SharedDataService) {
  console.log(this.sharedDataService.phoneNumber)// 12345678

}
  • Related