Pass Data from a Page to Provider

Hi,

Is it possible to pass data from Page to Provider.?
If yes, how we can do it.

My HTML is:

<ion-item>
		<ion-label floating>Search anything...</ion-label>
		<ion-input type="text" [(ngModel)]="search"></ion-input>
	 </ion-item>

and my Provider is

 constructor(public http: Http) {
		
		this.http.get('http://xyz.com/api/abc.php/?search=**SearchFromHtmlPage**').map(res => res.json()).subscribe(
			data=>{
				this.posts = data.records;
				
			});
	}

I want to pass value of search of html page to provider in the link

Thanks.

1 Like

It doesn’t make much sense to be doing that in the constructor. Assuming you’re injecting the provider in the page, the value won’t be available yet. I would define a getStuff method in the provider that takes an argument, and then call that from the page when you have the parameter defined.

Thanks Robert.
It helped.

IS there a possibility of sending me the sample code of how would you do that?