我正在学习离子的所有东西。 Typescript,Angular和其他一些构成Ionic的技术对我来说都是新的。
运行以下代码:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { CategoriesServiceProvider } from '../../providers/categories-service/categories-service';
import { CategoryPage } from '../category/category';
/**
* Generated class for the CategoriesPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-categories',
templateUrl: 'categories.html',
providers: [CategoriesServiceProvider]
})
export class CategoriesPage {
constructor(public navCtrl: NavController, public navParams: NavParams, private categories: CategoriesServiceProvider) {
}
quizCategories: any;
getCategories(){
this.categories.getCategories().then(question_categories => {
if(question_categories.categories){
this.quizCategories = question_categories.categories;
console.log(this.quizCategories);
}
});
}
}
我收到以下错误:
我添加了第28行,以检查 question_categories 是否正在返回数据,但同时检查和确定第29行上的分配会产生同样的问题。
我尝试读取的json数据如下:
{
"categories":
[
{
"category": {
"name": "Level 1",
"count": "1",
"tid": "3"
}
},
{
"category": {
"name": "Level 2",
"count": "2",
"tid": "1"
}
}
]
}