我似乎无法让这些一起工作。我正在使用 Aurelia CLI,并以类似的方式成功地对其他库(如 select2、spin、moment 和 numeric)进行了操作。但我似乎无法让 toastr 工作。这是我到目前为止所拥有的。
首先我跑了npm install toastr --save
and typings install dt~toastr --global --save
In aurelia.json
,在vendor-bundle.js部分,我添加了一个依赖项,如下所示:
"jquery",
{
"name": "toastr",
"path": "../node_modules/toastr/build",
"main": "toastr.min",
"resources": [
"toastr.min.css"
],
"deps": ["jquery"]
}
更新:重现的完整步骤
我安装了这些工具的以下版本:node (6.3.0)、npm (3.10.3)、au (0.17.0)
打开命令提示符并键入:
au new au-toastr
3 (Custom)
2 (Typescript)
3 (Sass)
1 (configure unit testing)
1 (Visual Studio Code)
1 (create project)
1 (install project dependencies)
cd au-toastr
npm install jquery --save
npm install toastr --save
typings install dt~jquery --global --save
typings install dt~toastr --global --save
然后打开aurelia.json
在编辑器中并添加
"jquery",
{
"name": "toastr",
"path": "../node_modules/toastr/build",
"main": "toastr.min",
"resources": [
"toastr.min.css"
],
"deps": ["jquery"]
}
到依赖项的底部。
注释掉第 1839 行(declare var $: cssSelectorHelper;
) on typings/globals/angular-protractor/index.d.ts
由于与 jquery 的 .d.ts 文件冲突。
Replace app.ts
内容与
import * as toastr from 'toastr';
export class App {
activate() {
toastr.info('blah');
}
}
OR
import 'toastr';
export class App {
activate() {
toastr.info('blah');
}
}
Type au run
在命令提示符中,然后打开浏览器并导航到命令行显示应用程序可用的 URL(通常http://localhost:9000
).
尝试1
import 'toastr';
export class ViewModel {
activate() {
toastr.info('blah');
}
}
Error: ReferenceError:toastr 未定义
尝试2
import {autoinject} from 'aurelia-framework';
import 'toastr';
@autoinject()
export class ViewModel {
constructor(private toastr: Toastr) {
}
activate() {
this.toastr.info('blah');
}
}
Error: 类型错误:this.toastr.info 不是一个函数
尝试3
import * as toastr from 'toastr';
export class ViewModel {
activate() {
toastr.info('blah');
}
}
Error: 类型错误:toastr.info 不是函数
尝试4
import {autoinject} from 'aurelia-framework';
import * as toastr from 'toastr';
@autoinject()
export class ViewModel {
constructor(private toastr: Toastr) {
}
activate() {
this.toastr.info('blah');
}
}
Error: 类型错误:this.toastr.info 不是一个函数
当我运行时,以上所有内容都会正确转换au build
从命令行。我没有收到任何错误。
我不知道我错过了什么或者我还可以尝试什么。任何帮助将不胜感激!
UPDATE:我的猜测是存在错误aurelia-cli
或者更有可能的是,我在某种程度上错误地处理了包裹aurelia-cli
加载机制。当我从他们的网站获取打字稿框架(使用 jspm 作为模块加载器)并按照上面相同的步骤操作时,toastr 工作得很好。
有什么想法可以让它与 aurelia-cli 一起使用吗?