のプロパティ「変数名」を設定することはできません私のcartCount
とwishlistCount
が正常に例外:未定義
更新されて1
constructor(public navCtrl: NavController,
public productServices:Products,
public loadingCtrl: LoadingController) {
this.productServices.getCartCount(function(data){
console.log("checking getCartCount" +JSON.stringify(data));
this.cartCount=data.count;
})
this.productServices.getWishlistCount(function(data){
console.log("checking getWishlistCount" +JSON.stringify(data));
this.wishlistCount = data.count;
})
console.log("invoking the ionviewload " +this.cartCount);
console.log("invoking the ionviewload " +this.wishlistCount);
}
以下はい私であるように私は私のコンストラクタ内で書かれたGETリクエストを持っていますconstructor()
は一度だけ実行されます。ビューが表示されたときにget要求を行う必要があります。ので、ここで私はこの
ionViewDidLoad(){
console.log("invoking the Home page ionView did load ");
this.productServices.getCartCount(function(data){
console.log("checking getCartCount" +JSON.stringify(data));
this.cartCount=data.count;
})
this.productServices.getWishlistCount(function(data){
console.log("checking getWishlistCount" +JSON.stringify(data));
this.wishlistCount = data.count;
})
console.log("invoking the ionviewload " +this.cartCount);
console.log("invoking the ionviewload " +this.wishlistCount);
}
を達成しようとするが、私は
例外としてエラーを取得しています何
:未定義
のプロパティ「cartCount」を設定することはできません、他の方法がありますいつでも私のビューが表示されたら取得要求を書く。
UPDATE: 私products.tsが
getCartCount(callbackFn: (productsArray: any) => void){
this.restService.get('/getCartCount', (data)=>{
console.log("invoking get CartCount details");
callbackFn(data);
},() => {
callbackFn([])
})
}
getWishlistCount(callbackFn: (productsArray: any) => void){
this.restService.get('/getWishlistCount', (data)=>{
console.log("invoking get WishlistCount details");
callbackFn(data);
},() => {
callbackFn([])
})
}
ファイルをチェックし、rest.tsが
get(url:string, successCallbackFn: (data: any)=>void, errorcallbackFn:()=>void) {
console.log("Calling " + this.configurator.restServerBaseUrl + url);
var authdetails = ""
if (this.tokenNeeded(url)) {
authdetails += '&user_id=' + this.userId;
authdetails += '&access_token=' + this.authToken;
authdetails += "&"
}
this.http.get(this.configurator.restServerBaseUrl + authdetails + this.configurator.restServerControllerUrl + url).subscribe(
result => successCallbackFn(result.json()),
error => errorcallbackFn())
}
あなたは 'productServices'を共有していただけますか? – ranakrunal9
@ ranakrunal9あなたは私のコンストラクタコードが正常に動作しているのを見ることができます。しかし私は私の意見がロードされたときに実行される要求を取得したい –
'OnInit'で試してみましたか? – ranakrunal9