Problem with subjectID

hi, i am new in ionic 2
i have get subjectID from another page through navParams
but when i implemented it in afunction found error:
"Uncaught (in promise): TypeError: Cannot read property ‘SubjectID’ of undefined"
here is my code:
in provider:
subjectBasedAttnd( AuthToken: string, SubjectID: string) {
let headers = new Headers({
‘AuthToken’: AuthToken
});

let options = new RequestOptions({
  headers: headers
});
return new Promise(resolve => {
  this.http.get("http://122.160.53.175:83/smartrollcall/api/WebRequest/GetDateWiseAttendance?StartDate="+" "+"&EndDate="+" "+"&SubjectID="+SubjectID, options)
    .map(res => res.json())
    .subscribe(
    data => { resolve(data) },
    err => { console.log(err) }
    );
});

}

in page.ts:
subject: any;
attendenceList: any;
item: any

constructor(public navCtrl: NavController,
public navParams: NavParams,
public storage: Storage,
public userProvider: UserProvider, ) {
this.subject = navParams.get(‘item’); // getting value

//console.log('id: ' + this.subject.SubjectID);
this.subjectAttendence();

}

subjectAttentList(){
return this.attendenceList;
}

subjectAttendence() {
console.log(‘subject clicked’);
this.storage.get(‘token’).then((value) => {
console.log('subtoken: ’ + JSON.parse(value).AuthToken);
this.userProvider.subjectBasedAttnd(JSON.parse(value).AuthToken, this.subject.SubjectID).then(data => {
console.log('list: ’ + data)
this.attendenceList = data;
});
});
}

ionViewDidLoad() {

console.log('ionViewDidLoad SubjectDetailsPage');

}

}

Looking at your code, It can only happen if you’ve not passed value from other page. So, your this.subject variable doesn’t get initialized with any value and when you use it in your subjectAttendence method, it gives error.

Please check value of your console log which you’ve put in your constructor, whether everytime you’re getting it or not.

And if you’re not getting then please check your other page’s code from which you’re navigating to this page.

bt i have already passed the value(item) from another page and in this page i have get the value through navParams(checked in browser at debug point). it is showing all the property of value(subject).

what is your output of
console.log(this.subject)

output of console.log(this.subject) is :[object Object]

can you give us output for console.log(JSON.stringify(this.subject))
because [object object] doesn’t help.

problem solved, don’t know how but my vsCode stopped responding after couple of minute. then i have restarted it. the code has worked after restart vscode. thanks for response. :):blush::blush:

good :ok_hand: :+1::+1: