[英]How do I import and use module using core JS in NativeScript
I am new to NativeScript and am trying to use the FancyAlert NPM module: 我是NativeScript的新手,正在尝试使用FancyAlert NPM模块:
https://github.com/NathanWalker/nativescript-fancyalert https://github.com/NathanWalker/nativescript-fancyalert
In their readme, they show a very simple example using TypeScript, like this: 在自述文件中,他们展示了一个使用TypeScript的非常简单的示例,如下所示:
import { TNSFancyAlert, TNSFancyAlertButton } from "nativescript-fancyalert";
.
.
.
public showSuccess() {
TNSFancyAlert.showSuccess(
"Success!",
"Fancy alerts are nice.",
"Yes they are!"
);
}
and in their XML file, they simply call it like normal: 在他们的XML文件中,他们像正常一样简单地调用它:
<Button text="Alert Success" tap="{{showSuccess}}" />
So I am not using TypeScript. 所以我不使用TypeScript。 I cannot get this simple alert to work.
我无法获得此简单的警报来工作。 I have tried:
我努力了:
in my main-view-model.js
在我的main-view-model.js中
const fancyAlert = require("nativescript-fancyalert");
.
.
.
fancyAlert.showSuccess(
"Success!",
"You are logged in.",
"Success!"
);
not working. 不工作。
Can anyone help me to use this module using core JS? 谁能帮助我使用核心JS使用此模块?
Thank you. 谢谢。
Try: fancyAlert.TNSFancyAlert.showSuccess()
. 试试:
fancyAlert.TNSFancyAlert.showSuccess()
。
[EDIT] This really should work, as it's a mirror of the solution given in the issue filing linked by Narendra Mongiya in your question. [编辑]这确实应该起作用,因为它反映了Narendra Mongiya在您的问题中所链接的问题文件中给出的解决方案。 One thing to keep in mind is that it's a Promise, so let's add a
catch()
block in there to reveal any errors. 要记住的一件事是它是一个Promise,所以让我们在其中添加
catch()
块以揭示任何错误。
const fancyAlert = require("nativescript-fancyalert");
// ...
fancyAlert.TNSFancyAlert.showSuccess(
"Success!",
"You are logged in.",
"Success!"
)
.then((resolution) => {
console.log("[TNSFancyAlert] showSuccess() succeeded.", resolution);
})
.catch((error) => {
console.error("[TNSFancyAlert] showSuccess() failed.", error);
});
You may also find that you're simply calling it from the wrong place in your code. 您可能还会发现只是在错误的代码位置调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.