मैं एक कोड है कि इस तरह दिखता है:Angular2 'इस' अपरिभाषित है
export class CRListComponent extends ListComponent<CR> implements OnInit {
constructor(
private router: Router,
private crService: CRService) {
super();
}
ngOnInit():any {
this.getCount(new Object(), this.crService.getCount);
}
ListComponent कोड इस
@Component({})
export abstract class ListComponent<T extends Listable> {
protected getCount(event: any, countFunction: Function){
let filters = this.parseFilters(event.filters);
countFunction(filters)
.subscribe(
count => {
this.totalItems = count;
},
error => console.log(error)
);
}
और CRService से उपयुक्त सेवा कोड टुकड़ा है यह:
getCount(filters) {
var queryParams = JSON.stringify(
{
c : 'true',
q : filters
}
);
return this.createQuery(queryParams)
.map(res => res.json())
.catch(this.handleError);
}
अब जब मेरे ngOnInit()
रन, मुझे एक त्रुटि मिलती है:
angular2.dev.js:23925 EXCEPTION: TypeError: Cannot read property 'createQuery' of undefined in [null]
ORIGINAL EXCEPTION: TypeError: Cannot read property 'createQuery' of undefined
तो मूल रूप से return this.createQuery(queryParams)
कथन में शून्य होगा। क्या किसी के पास कोई विचार है कि यह कैसे संभव है?
आपको क्यों लगता है कि यह .createQuery' मौजूद है? –
क्या यह "सामान्य" है कि आपके 2 वर्गों में एक बंद ब्रैकेट गुम है? –
मैंने अभी अनावश्यक भागों को छोड़ दिया है, कोड अन्यथा सिंटैक्टिक रूप से सही है। :) समस्या '.createQuery' के साथ नहीं है, यह 'यह' के साथ है। – Sleeper9