NativeScript 在页面标签上添加 xml 命名空间

NativeScript adding xml namespace on Page tag

我是 NativeScript 的新手。我使用 Angular 空白模板创建了一个新项目。导航是使用 page-router-outlet 完成的。我想在页面级别包含一个 xmlns 属性。据我所知,整个代码都呈现在全局页面属性中。我已经看到我可以通过将页面注入组件并更改它的属性来修改页面属性,但是我如何为 xmlns 执行此操作?

此致, 弗拉德

要在基于 Angular 的应用程序中注册一个 UI 组件,您应该使用 registerElement 而不是 XML 命名空间(这是 NativeScript Core 中使用的概念)。现在大多数插件作者都在为你做这项工作,但仍然有一些插件没有迁移到使用最新技术,所以在某些情况下,我们应该手动注册 UI 元素。

我创建了 this test applicaiton,它演示了如何在 Angular 中使用 nativescript-stripe。以下是启用和使用插件的步骤。

安装

npm i nativescript-stripe --save

app.module.ts中注册UI元素完成here

import { registerElement } from "nativescript-angular/element-registry";
registerElement("CreditCardView", () => require("nativescript-stripe").CreditCardView);

根据插件README中的要求在main.ts中添加the following

import * as app from "tns-core-modules/application";
import * as platform from "tns-core-modules/platform";

declare const STPPaymentConfiguration;
app.on(app.launchEvent, (args) => {
    if (platform.isIOS) {
        STPPaymentConfiguration.sharedConfiguration().publishableKey = "yourApiKey";
    }
});

在您的 HTML (example)

中使用插件
<CreditCardView id="card"></CreditCardView>