Reputation: 1371
I am new to Ionic. I got a location page, and under location/location.page.ts file, there is an empty constructor generated automatically as bellow:
constructor() { }
The page runs fine with it. However, if I add any parameter to the constructor, the page cannot loaded.
constructor(private httpProvider: HttpProvider, public geolocation: Geolocation) { }
Do I have to do anything else when add parameters to constructor? I am working on an Ionic 4 project. I also added it in the appmodule.ts file. Am I still missing anything?
Thanks.
Upvotes: 0
Views: 1980
Reputation: 4702
Also for other services
use
{ providedIn: 'root' }
like this in the services.
@Injectable(
{ providedIn: 'root' }
)
Upvotes: 0
Reputation: 2398
You need to import the HttpModule in your app.modules.ts like so :
import { HttpModule } from '@angular/http';
Then add add it to your imports :
imports: [
///
HttpModule,
///
]
In the same file you need to declare your Gelocation provider :
import { Geolocation } from '@ionic-native/geolocation';
This time add Geolocation to the providers array.
Now in your LocationPage, your constructor needs to look like:
constructor(private http: Http, private location: Geolocation){
///
}
provided that you have installed the appropriate npm packages as explained here
Upvotes: 1