2016-12-16 44 views
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') 

我在做什么错? :/

回答

5

在角2的语法在HTML宣布了一个让如下:

let-myName="item" 
你的情况

let-pokemon="item" 

起初它有点怪,但它完全令感。 对于完整的例子看看here

+0

它听起来完全听起来很奇怪,NativeScript没有多大帮助,因为它们的默认示例是'let-item =“item”',这让我觉得语法是'let-项= “myCustomName”'。感谢您的澄清! –