Nativescript 和 ListView,项目未定义
Nativescript and ListView, item undefined
我正在尝试使用 NativeScript 进行一些实验,但我遇到了一些奇怪的错误,我无法理解要点。
我的组件中有一个简单的口袋妖怪列表:
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')
我做错了什么? :/
在 Angular-2 中,在 HTML 中声明 let 的语法如下:
let-myName="item"
你的情况:
let-pokemon="item"
起初有点奇怪,但完全有道理。
有关完整示例,请查看 here
我正在尝试使用 NativeScript 进行一些实验,但我遇到了一些奇怪的错误,我无法理解要点。
我的组件中有一个简单的口袋妖怪列表:
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')
我做错了什么? :/
在 Angular-2 中,在 HTML 中声明 let 的语法如下:
let-myName="item"
你的情况:
let-pokemon="item"
起初有点奇怪,但完全有道理。 有关完整示例,请查看 here