I'm trying to access an API with angularResource.get(params)
The model for the class looks like this:
export class d_stp_searchbar implements Id_stp_searchbar {
lperiode?: number;
private _lsichtweise: number;
scode?: string;
sbezeichnung?: string;
bezeichnungLabel: string;
set lsichtweise(value) {
this._lsichtweise = value;
this.bezeichnungLabel = this.lsichtweise === 5 ? "Name" : "Bezeichnung";
}
get lsichtweise() {
return this._lsichtweise;
}
public bezeichnung() {
if (this.lsichtweise === 5) {
this.bezeichnungLabel = "Name";
} else {
this.bezeichnungLabel = "Bezeichnung";
}
}
}
The function, where i call the api looks like the following:
searchStundenplan(params: d_stp_searchbar): angular.IPromise<any> {
this.searchStundenplanParams = params;
this.localStorageService.set("searchStundenplanParams", this.searchStundenplanParams);
return this.searchStundenplanResource.get(params)
.$promise.then((result) => {
this.searchStundenplanResult = result;
this.searchStundenplanResultChangedNotify();
});
}
The problem I'am facing is, that the URL that will be called looks like this:
GET /api/search/Stundenplan?_lsichtweise=1&bezeichnungLabel=Bezeichnung&lperiode=86
but I want, that instead of _lsichtweise lsichtweise will be used.
Do I use it wrong or does somebody know, why not the public property lsichtweise is used?
Thanks in advance
lsichtweisein your classd_stp_searchbar. You created a magic functiongetbutangular.IPromisedoes only recognize class vars and ignores the magic getter function. Just add a public class propertylsichtweise: number;. Maybeangular.IPromisewill call the magic getter function and you will be fine.angular.IPromise. Which solution you would prefer?d_stp_searchbarwas only instantiated properly the first time we called it. So your comment was not the solution, but a gamechanger for further investigations. Thank you!