使用Angular2的Nativescript是否需要特殊的* ngFor?

缺口

我正在创建此移动应用程序,其中我必须列出一些标签。代码如下:

@Component({
    selector: 'code-m',
    template: `
                <StackLayout dock="top" orientation="vertical" style="height:90%;" backgroundColor="lightgray">
                    <label text="Code Methods" style="background-color:red;"></label>
                    <Label *ngFor="let item of items" [text]="item"></Label>
                    <label text="test" style="background-color:blue;"></label>
                </StackLayout>
        `
})
export class CodeMethodsComponent{
    public items:Array<string> = [];

    constructor(){
        this.items.push("Default");
        this.items.push("Validation");
        this.items.push("Filter");
        this.items.push("Business");
        this.items.push("Provisional");
        console.log(this.items);
        console.log("test")
    }
}

带有* ngFor的标签根本不会显示。感觉像循环根本不起作用。我检查了Nativescript网站上的文档,它似乎具有较旧的版本(使用#而不是let),该版本也不起作用。如果您可以引导我解决我的错误,并且可能的话建议我一个地方(Nativescript的网站除外)来获取帮助,我将非常感激。

可以公平地说,第一个和最后一个标签显示正确。

[EDIT]似乎*ngFor="let item of items无法识别items数组。尝试使用{{}}进行推断,但这样做有误。

缺口

解决此问题的方法是路由器的实现不正确。

我正在使用onClick router.navigate()从我的主要组件路由到该组件。这样路由,不知道为什么,似乎正确地路由到目的地,它将创建任何静态标签/按钮/等。但不是所有依赖* ngFor的东西(即使* ngIf也不起作用)。

总而言之,使用[nsRouterLink]而不是router.navigate()进行导航固定了我的代码。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章