【发布时间】:2018-06-14 09:37:54
【问题描述】:
在 Windows 10 操作系统中托管的 Angular 6 项目中,
我启动命令:
npm install --save @types/winrt-uwp
它应该允许我使用 winRT 功能和编写代码:
public showToast(message, iconUrl) {
if (
typeof Windows !== "undefined" &&
typeof Windows.UI !== "undefined" &&
typeof Windows.UI.Notifications !== "undefined"
) {
var notifications = Windows.UI.Notifications;
var template = notifications.ToastTemplateType.toastImageAndText01;
var toastXml = notifications.ToastNotificationManager.getTemplateContent(
template
);
var toastTextElements = toastXml.getElementsByTagName("text");
toastTextElements[0].appendChild(toastXml.createTextNode(message));
var toastImageElements = toastXml.getElementsByTagName("image");
var newAttr = toastXml.createAttribute("src");
newAttr.value = iconUrl;
var altAttr = toastXml.createAttribute("alt");
altAttr.value = "toast graphic";
var attribs = toastImageElements[0].attributes;
attribs.setNamedItem(newAttr);
attribs.setNamedItem(altAttr);
var toast = new notifications.ToastNotification(toastXml);
var toastNotifier = notifications.ToastNotificationManager.createToastNotifier();
toastNotifier.show(toast);
}
}
但是当我想启动项目时,我收到了错误消息:
错误 TS2552:找不到名称“Windows”。您指的是“窗口”吗?
但是我可以创建一个文件node_modules/@types/winrt-uwp/index.d.ts,其中包含
...
declare namespace Windows {
...
}
..
你对这个问题有什么想法吗?
【问题讨论】:
标签: angular typescript uwp windows-runtime angular6