将路由器链接添加到 Angular NativeScript 中的段落

Adding router links to a paragraph in Angular NativeScript

正在尝试格式化包含多个文本链接的段落或句子。这些链接将是路由器链接,而不是外部 Web 链接。

看起来您可以使用 FormattedString 和 Span 格式化文本,但您似乎也无法将 nsRouterLink 添加到 Span。

<Label class="terms">
    <FormattedString>
        <Span text="By creating an account, you agree to the our "></Span>
        <Span
            text="Terms of Use"
            class="link"
            [nsRouterLink]="['/policies/terms-of-use']"
            pageTransition="slideLeft"
        ></Span>
        <Span text=" and "></Span>
        <Span
            text="Privacy Policy"
            class="link"
            [nsRouterLink]="['/policies/privacy-policy']"
            pageTransition="slideLeft"
        ></Span>
        <Span text="."></Span>
    </FormattedString>
</Label>

如果我可以让整个东西都可以点击,我可以将所有东西都放在一个按钮中,但是正如您在示例中看到的那样,那里有两个单独的链接。

遗憾的是,尚不支持 Span 上的点击事件。 open feature request 已经有一段时间了。

尽管您可以在 Github 中找到一个 example 的识别 tap 的本地代码位。您可能必须实现相同的功能并从侦听器调用导航方法。