Nativescript和ListView,项目未定义 [英] Nativescript and ListView, item undefined
本文介绍了Nativescript和ListView,项目未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用NativeScript进行实验,但是遇到一些奇怪的错误,我无法理解这一点.
I m trying to make some experiments with NativeScript, but I m facing some weird error, and I can't get the point.
我的组件中有一个简单的口袋妖怪列表:
I m having a simple list of pokemons inside of my component :
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>
当我尝试启动应用程序时,我的控制台出现以下错误:
When I try to start the application, I'm having the following error in my console :
Error in components/pokemonList/pokemonList.html:4:20 caused by: undefined is not an object (evaluating 'self.parentView.context.pokemon.name')
我在做什么错? :/
推荐答案
在Angular-2中,用于在HTML中声明let的语法如下:
In Angular-2 the syntax for declaring a let in your HTML is the following:
let-myName="item"
根据您的情况:
let-pokemon="item"
At first its kinda strange but it totally make sense. For full lenght example take a look here
这篇关于Nativescript和ListView,项目未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文