Getting the following error when running ionic serve:
Typescript Error
Expected 1 arguments, but got 0.
It also highlights this line in the code:
this.search.getEmployees()
The code will function properly via the browser (refrbut wont compile for mobile.
Here is my Code Page:
import { Component } from ‘@angular/core’;
import { IonicPage, NavController, NavParams } from ‘ionic-angular’;
import { Http } from ‘@angular/http’;
import xml2js from ‘xml2js’;
import { SearchProvider } from ‘…/…/providers/search/search’
import { CallNumber } from ‘@ionic-native/call-number’;
@IonicPage()
@Component({
selector: ‘page-results’,
templateUrl: ‘results.html’,
providers:[SearchProvider]
})
export class ResultsPage {
employees$: SearchProvider[]
constructor(public navCtrl: NavController, public navParams: NavParams, public search: SearchProvider, private callNumber: CallNumber) {
this.employees$ = [];
}
ionViewDidLoad(){
var employees;
this.search.getEmployees()
.subscribe(data => {
xml2js.parseString(data.text(), function (err, result) {
employees = result.qdbapi.record;
return data;
});
this.employees$ = employees;
console.log (this.employees$);
return data;
});
}
@ewehrmann Well, you have your answer in the error:
You have:
import { SearchProvider } from ‘…/…/providers/search/search’
You inject it with public search: SearchProvider
, and then you use it like:
this.search.getEmployees().subscribe(data => ...)
You aren’t passing any parameters to getEmployees()
like getEmployees(someValue)
.
Look at your class SearchProvider
and see what it expects in getEmployees
.
@Injectable()
export class SearchProvider {
getEmployees(someParam: SomeType) {
// do some stuff
}
}
I don’t know what is in your provider, but should be similar to the above.
As a side note, you have employees$: SearchProvider[]
. I don’t know exactly why you have this but I think you shouldn’t have an array of providers (normally, providers should be injected).
Additionally, the chicanery involving employees
is a hideous mix of rx and callbacks. It would look much cleaner if you found (or wrote) a shim that looks something like this:
parseXmlEmployees(xml: string): Observable<Employee[]> {
return Observable.create((obs) => {
xml2js.parseString(xml, (err, result) => {
obs.next(result.qdbapi.record);
});
});
}
…that way you can use switchMap
cleanly like so:
getEmployees(): Observable<Employee[]> {
return this.oldGetEmployees().pipe(
switchMap(xml => this.parseXmlEmployees(xml)));
}
1 Like
Thanks! I had the variable in the constructor of the provider so I guess I didn’t need to pass it into the function.