freddi andrew
freddi andrew

Reputation: 45

nsRouterLink Nativescript from dynamic data from service

i have array from Service

private items = new Array<Item>(
        { id: 1, name: "Batman", link: "batmanscreen" },
        { id: 3, name: "doraemon", link: "dorascreen" },
        ...........

,

XML Component like :

<ActionBar title="Details" class="action-bar"></ActionBar>
<FlexboxLayout flexDirection="column" class="page">
    <FlexboxLayout class="m-15">
        <Label class="h2" [text]="item.id + '. '"></Label>
        <Label class="h2" [text]="item.name"></Label>
    </FlexboxLayout>
    <Label class="h4" [text]="item.link"></Label>
    <Label [nsRouterLink]="['/item.link']" text="go TO Screen" ></Label>
</FlexboxLayout>

and the result on android emulator when link got click :

EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'item.link'

i expect become nsRouterLink = "['/batmanscreen']" , but can not find any guide in nativescript navigation, please guide. in angular 2 web i can handle it, but i don`t know how to do it in nativescript..

thank you.

Upvotes: 0

Views: 559

Answers (2)

Vladimir Amiorkov
Vladimir Amiorkov

Reputation: 2921

Simply do the routes like this:

private items = new Array<Item>(
        { id: 1, name: "Batman", link: "/batmanscreen" },
        { id: 3, name: "doraemon", link: "/dorascreen" },

And do the binding as normally you would in Angular's HTML (when working with {N} + Angular there is not XML):

<Label [nsRouterLink]="item.link" text="go TO Screen" ></Label>

Upvotes: 1

Eddy Verbruggen
Eddy Verbruggen

Reputation: 3550

So you're expecting ['/item.link'] to evaluate to ['/batmanscreen']? That '/item.link' is just a string literal so it's not replaced by 'batmanscreen' as you'd hope.

Try like this instead: ['/' + item.link].

Upvotes: 1

Related Questions