首页 文章

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

提问于
浏览
0

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

最好的问候,弗拉德

1 回答

  • 0

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

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

    Installation

    npm i nativescript-stripe --save
    

    Register the UI elementapp.module.ts 完成here

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

    Add the following in main.ts 根据插件自述文件的要求

    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";
        }
    });
    

    Use the plugin in your HTMLexample

    <CreditCardView id="card"></CreditCardView>
    

相关问题