我想在我的Angular项目中使用Chart.js.在以前的Angular2版本中,我使用'chart.loader.ts'做得很好,它有:
export const { Chart } = require('chart.js');
Run Code Online (Sandbox Code Playgroud)
然后在组件代码中我就是
import { Chart } from './chart.loader';
Run Code Online (Sandbox Code Playgroud)
但升级到cli 1.0.0和Angular 4之后,我收到错误:"找不到名称'require'".
要重现错误:
ng new newapp
cd newapp
npm install chart.js --save
echo "export const { Chart } = require('chart.js');" >> src/app/chart.loader.ts
ng serve
Run Code Online (Sandbox Code Playgroud)
在我的'tsconfig.json'中,我有
"typeRoots": [
"node_modules/@types"
],
Run Code Online (Sandbox Code Playgroud)
在'node_modules/@types/node/index.d.ts'中有:
declare var require: NodeRequire;
Run Code Online (Sandbox Code Playgroud)
所以我很困惑.
顺便说一句,我经常遇到警告:
[tslint] The selector of the component "OverviewComponent" should have prefix "app"(component-selector)
Run Code Online (Sandbox Code Playgroud)
虽然我在'.angular-cli.json'中设置了"前缀":"".可能是因为从'angular-cli.json'改为'.angular-cli.json'的原因?
我刚刚在Windows上安装了Qt5.4.1 MSVC2013,当我尝试构建项目时,遇到了类似的错误
Unknown module(s) in QT: core gui widgets.
Run Code Online (Sandbox Code Playgroud)
然后我添加一个用户环境变量路径
D:\Program Files\Qt\5.4\msvc2013_64;
Run Code Online (Sandbox Code Playgroud)
但问题仍然存在.
我搜索互联网,但似乎没有人遇到过类似的问题......这真让我感到困惑.
假设我有一个已经是 git repo“sub”的目录,现在我希望它成为我新创建的超级目录“sup”的子树。
我已经搜索了文档,但所有教程都是关于添加远程存储库或从现有提交中拆分。如何将现有的 git 存储库添加到主 git 存储库?
使用git subtree add --prefix=sub sub会给出警告子已经存在。
我发现使用sort而不比较函数会导致错误的答案,我不知道原因.
var a = [823564440,115438165,784484492,74243042,114807987,137522503,441282327,16531729,823378840,143542612]
a.sort()
a.sort((a,b) => a-b)
Run Code Online (Sandbox Code Playgroud)
这两个人应该在我的脑海中给出相同的结果,但他们没有.显然后者是正确的.
a.sort()
[114807987, 115438165, 137522503, 143542612, 16531729, 441282327, 74243042, 784484492, 823378840, 823564440]
a.sort((a, b) => a-b)
[16531729, 74243042, 114807987, 115438165, 137522503, 143542612, 441282327, 784484492, 823378840, 823564440]
Run Code Online (Sandbox Code Playgroud)
谁能告诉我这背后的原因?
基本上我想要这样的东西(现在肯定不行).我完成res.send()后可以使用事件来实现client.get()吗?
var events = require('events');
var eventEmitter = new events.EventEmitter();
var response = {};
var ids = [...];
for (id in ids) {
this.client.get(id1, function(err, obj) {
if (!err) {
response[id.toString()] = obj;
}
});
}
res.send({
response
});
Run Code Online (Sandbox Code Playgroud)