Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70924

Error when calling method in Provider

$
0
0

@boyfunky1 wrote:

I have the following component

newsfeed.ts

import { Component, Inject } from ‘@angular/core’;
import { NavController, Tabs } from ‘ionic-angular’;
import { AuthService } from ‘…/…/services/auth/auth.service’;
import { ReportService } from ‘…/…/services/reports/report.service’;
import { EnvVariables } from ‘…/…/app/environment-variables/environment-variables.token’;

@Component({
selector: ‘page-newsfeed’,
templateUrl: ‘newsfeed.html’
})

export class Newsfeed {
report_list: {};
apiUrl: any;

static get parameters()
{
return [[Tabs]];
}

constructor(
public tab: Tabs,
public navCtrl: NavController,
public authService: AuthService,
public reportService: ReportService,
@Inject(EnvVariables) public envVariables) {

this.tab = tab;

}

ionViewDidLoad() {
this.reportList();
}
openReportTab() {
this.tab.select(2);
}

reportList() {
this.reportService.get_report_list().subscribe((results) => {
this.report_list = results;
})

}

}

and the following service

report.service.ts

import { AuthHttp } from ‘angular2-jwt’;
import { Inject, Injectable } from ‘@angular/core’;
import { Storage } from ‘@ionic/storage’;
import { Http, Headers, Response, RequestOptions } from ‘@angular/http’;
import { Observable } from “rxjs/Observable”;
import { EnvVariables } from ‘…/…/app/environment-variables/environment-variables.token’;
import { GlobalErrorHandler } from ‘…/providers/error-handler’;
import { ToastHandler } from ‘…/providers/toasts’;

@Injectable()

export class ReportService {

constructor(public authHttp: AuthHttp, private http: Http, @Inject(EnvVariables) public envVariables){

  var headers = new Headers();
  headers.append("Accept", 'application/json');
  headers.append('Content-Type', 'application/json');
  var options = new RequestOptions({headers: headers});
}



public get_report_list(): Observable<Response> {
	console.log("get report list")
	var url = "/api/v1/newsfeed";
	return this.authHttp.get(this.envVariables.apiEndpoint + url)
 		.map(res => res.json().data)
}

}

In my code, I am calling the get_report_list method in the constructor of the newsfeed component but I keep getting this error which is completely absurd

Unhandled Promise rejection: Cannot read property ‘get_report_list’ of undefined ; Zone:
angular ; Task: Promise.then ; Value: [object Object] TypeError: Cannot read property ‘get_report_list’ of
undefined at Newsfeed.webpackJsonp.304.Newsfeed.reportList (http://localhost:8100/build/main.js:387:28) at
Newsfeed.webpackJsonp.304.Newsfeed.ionViewDidLoad (http://localhost:8100/build/main.js:362:14) at
ViewController._lifecycle (http://localhost:8100/build/vendor.js:18359:33) at ViewController._didLoad
(http://localhost:8100/build/vendor.js:18232:14) at Tab.NavControllerBase._didLoad
(http://localhost:8100/build/vendor.js:47611:18) at t.invoke
(http://localhost:8100/build/polyfills.js:3:8488) at Object.onInvoke
(http://localhost:8100/build/vendor.js:4796:37) at t.invoke
(http://localhost:8100/build/polyfills.js:3:8428) at r.run (http://localhost:8100/build/polyfills.js:3:3686)
at NgZone.run (http://localhost:8100/build/vendor.js:4665:62)

Completely confused and i dont know why this error exists. Can someone point me in the right direction?

Thanks

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>