- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在执行 Skycons 时遇到问题在我的 Angular 2 应用程序中。我已经通过 npm i skycons 安装了 Skycons。
typings.d.ts
declare module 'skycons'
weather.component.ts(负责 Skycons 的部分)
import * as Skycons from 'skycons';
import * as jQuery from 'jquery';
ngOnInit() {
this.todayDate();
this.getWeather();
this.findLocation(52.4069200, 16.9299300);
var skyconType = function (icon) {
if (icon === 'rain')
return Skycons.RAIN
else if (icon === 'snow')
return Skycons.SNOW
else if (icon === 'sleet')
return Skycons.SLEET
else if (icon === 'hail')
return Skycons.SLEET
else if (icon === 'wind')
return Skycons.WIND
else if (icon === 'fog')
return Skycons.FOG
else if (icon === 'cloudy')
return Skycons.CLOUDY
else if (icon === 'partly-cloudy-day')
return Skycons.PARTLY_CLOUDY_DAY
else if (icon === 'partly-cloudy-night')
return Skycons.PARTLY_CLOUDY_NIGHT
else if (icon === 'clear-day')
return Skycons.CLEAR_DAY
else if (icon === 'clear-night')
return Skycons.CLEAR_NIGHT
return Skycons.CLOUDY
}
jQuery(function () {
var skycons = new Skycons({ "color": "#111" })
jQuery('.skycon canvas').each(function (i, elem) {
skycons.add(elem, skyconType(elem.className))
})
skycons.play()
})
}
weather.component.html(负责 Skycons 的部分)
<div class="skycon">
<canvas width="84" height="84" id="icon" class="{{ weather.currently.icon }}">{{ weather.currently.icon }}</canvas>
</div>
{{ Weather.currently.icon }}
返回例如 string
“partly-cloudy-day”
这是我第一次在 Angular 应用程序中使用外部 JS 库。
在开发人员工具中,我收到两个错误(Angular 编译期间没有错误):
jQuery.Deferred exception: skycons.add is not a function TypeError: skycons.add is not a function
Uncaught TypeError: skycons.add is not a function
软件版本:
Angular CLI:1.7.4节点:9.4.0操作系统:win32 x64 Angular :2.4.10
最佳答案
假设您的 skycons 文件夹位于您的 node_modules 文件夹中,请尝试使用以下内容在您的 component.ts 文件中声明 Skycons 对象。
const Skycons = require("skycons")(window);
关于javascript - Angular 2 外部 JS 库 Skycons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49898457/
我正在创建一个基本的天气应用程序。它从开放天气API获取天气数据,然后显示温度和位置。我找到了 SKYCONS,并认为它们是向我的应用程序添加图标的一种很好且简单的方法。然而,他们不会出现。
我已经将 JavaScript 插件“Skycons”连接到雅虎天气 RSS 提要。我遇到的问题是多天可能会有相同的天气预报,并且因为插件从 ID 而不是类中提取图标,所以我无法再次提取相同的图标。
我正在使用基于此 youtube video 的天气应用程序 我有以下 code并且正在使用 Skycons.js 我现在遇到的问题是我正在尝试在其中实现暗模式。我的大部分功能都在运行,但是当我的暗模
我为免费代码营制作了这个天气应用程序,我决定使用 Skycons 的一些图标:http://darkskyapp.github.io/skycons/ 但是,无论我多么努力,我都无法更改页面上图标的对
我在执行 Skycons 时遇到问题在我的 Angular 2 应用程序中。我已经通过 npm i skycons 安装了 Skycons。 typings.d.ts declare module '
我正在使用 Skycons,它工作得非常好。但是当我有 2 个 Canvas ID 时,它会渲染第一个,但另一个将为空白。 在 JS 中我有: var icons = new Skycons({
作为我的第一个使用 API 的应用程序,我决定使用 Dark Sky API。我正在尝试为从 JS 文件生成的每个预测日添加动画 Skycons。我已阅读 StackOverflow 上有关 Skyc
我是一名优秀的程序员,十分优秀!