0
我試圖用NativeScript做一些實驗,但我面臨一些奇怪的錯誤,我不明白這一點。Nativescript和ListView,項目undefined
我米有小寵物的簡單列表我的組件裏面:
import {Component} from '@angular/core';
import {Http} from '@angular/http';
@Component({
selector:'pokemon-list',
templateUrl: 'components/pokemonList/pokemonList.html'
})
export default class PokemonList {
pokemons: Array<any>;
constructor(private http:Http){
this.pokemons = [
{name: 'Bulbi', url: 'google.com'}
];
}
}
並具有相關的下面的模板:
<StackLayout>
<Label text="Pokemons" class="h1 text-center"></Label>
<ListView [items]="pokemons">
<template let-item="pokemon">
<pokemon-item [name]="pokemon.name" [url]="pokemon.url"></pokemon-item>
</template>
</ListView>
</StackLayout>
當我嘗試啓動應用程序,我有在我的控制檯中出現以下錯誤:
Error in components/pokemonList/pokemonList.html:4:20 caused by: undefined is not an object (evaluating 'self.parentView.context.pokemon.name')
我在做什麼錯? :/
它聽起來完全聽起來很奇怪,NativeScript沒有多大幫助,因爲它們的默認示例是'let-item =「item」',這讓我覺得語法是'let-項= 「myCustomName」'。感謝您的澄清! –