ben şöyle bir kod vardır:Angular2 'bu' tanımsız
: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 kodu bu
@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)
);
}
Ve CRService uygun hizmet kod parçası olan budur
getCount(filters) {
var queryParams = JSON.stringify(
{
c : 'true',
q : filters
}
);
return this.createQuery(queryParams)
.map(res => res.json())
.catch(this.handleError);
}
ngOnInit()
numaralı telefonum çalışırken hata mesajı alıyorum:
angular2.dev.js:23925 EXCEPTION: TypeError: Cannot read property 'createQuery' of undefined in [null]
ORIGINAL EXCEPTION: TypeError: Cannot read property 'createQuery' of undefined
Temel olarak, return this.createQuery(queryParams)
ifadesindeki this
deyiminde boş bırakılacaktır. Bunun nasıl olabileceği hakkında bir fikri olan var mı?
Neden this.createQuery' var? –
, 2 sınıfınızın bir kapatma ayracına sahip olmadığı "normal" midir? –
Sadece gereksiz parçaları atladım, kod başka bir şekilde sözdizimsel olarak düzeltildi. :) Sorun '.createQuery' ile değil,' '' 'ile kendisi. – Sleeper9