Nativescript and ListView, item undefined

只谈情不闲聊 提交于 2019-12-25 04:04:26

问题


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'}
    ];
  }
}

And having the following template associated :

<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')

What am I doing wrong ? :/


回答1:


In Angular-2 the syntax for declaring a let in your HTML is the following:

let-myName="item"

in your case:

let-pokemon="item"

At first its kinda strange but it totally make sense. For full lenght example take a look here



来源:https://stackoverflow.com/questions/41184374/nativescript-and-listview-item-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!