【问题标题】:NativeScript adding xml namespace on Page tagNativeScript 在页面标签上添加 xml 命名空间
【发布时间】:2018-07-25 13:00:54
【问题描述】:

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

最好的问候, 弗拉德

【问题讨论】:

  • 使用 Angular 时,您创建的是 HTML 页面而不是 XML(就像在 NativeScript Core 项目中那样)。为什么需要将 XML 命名空间添加到 HTML 页面?
  • 我想添加 nativescript-stripe 插件(npmjs.com/package/nativescript-stripe),并在说明中说要在页面标签上包含 xmlns 代码
  • xmlns 仅用于带有 XML 页面的 nativeScript 代码。要在 Angular 中使用插件,您需要 Angular 说明(自述文件中缺少这些说明)。基本上,在你的模块文件中做这个github.com/triniwiz/nativescript-stripe/blob/master/angular/…,然后直接在你的HTML中使用标签<CreditCardView></CreditCardView>(当然添加参数)

标签: nativescript angular2-nativescript


【解决方案1】:

要在基于 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);

根据插件自述文件中的要求在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>

【讨论】:

  • 感谢您的宝贵时间。关于该插件仅在iOS上支持的部分,您是说该插件不能在Android上使用吗?据我所知,该项目的自述文件中没有任何地方写过,并且有一些部分是关于在 Android 上使用它的。
  • 你是绝对正确的 - 我一定弄错了自述文件。删除了我的声明
猜你喜欢
  • 1970-01-01
  • 2011-09-16
  • 2010-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多