mfr*_*het 0 javascript typescript nativescript angular
我试图用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'}
];
}
}
Run Code Online (Sandbox Code Playgroud)
并关联以下模板:
<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>
Run Code Online (Sandbox Code Playgroud)
当我尝试启动应用程序时,我的控制台中出现以下错误:
Error in components/pokemonList/pokemonList.html:4:20 caused by: undefined is not an object (evaluating 'self.parentView.context.pokemon.name')
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么 ?:/
在Angular-2中,在HTML中声明let的语法如下:
let-myName="item"
Run Code Online (Sandbox Code Playgroud)
在你的情况下:
let-pokemon="item"
Run Code Online (Sandbox Code Playgroud)
起初它有点奇怪,但它完全有道理.有关完整长度的示例,请查看此处
| 归档时间: |
|
| 查看次数: |
497 次 |
| 最近记录: |