0

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 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

It totally sounds strange at first and NativeScript does not help much because their default example is let-item="item", which made me think that the syntax was let-item="myCustomName". Thanks for the clarification!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.