我是npm中配置部分的新手,我试图在使用angular-cli(ng init)创建的angular 2项目中使用handsontable库。我为它添加了打字稿定义。
这是我的app.compponent.ts
import { Component } from '@angular/core'; import 'handsontable/dist/handsontable.full.js'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app works!'; ngOnInit() { } ngAfterViewInit() { const myData = [ ["1", "2", "3", "4", "5", "6"] ]; const config = { data: myData, colHeaders: ['A', 'B', 'C', 'D', 'E', 'F'], startRows: 5, startCols: 5, minSpareCols: 1, //always keep at least 1 spare row at the right minSpareRows: 1 //always keep at least 1 spare row at the bottom, }; ($("#test")).handsontable(config); } }
app.component.html
index.html
AngularStart2 Loading...
tsconfig.js
{ "compilerOptions": { "baseUrl": "", "declaration": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": ["es6", "dom"], "mapRoot": "./", "module": "es6", "moduleResolution": "node", "outDir": "../dist/out-tsc", "sourceMap": true, "target": "es5", "typeRoots": [ "../node_modules/@types" ] } }
给我错误:
ReferenceError: Handsontable is not defined at r.fn.init.$.fn.handsontable (http://localhost:4200/vendor.bundle.js:87583:26) at AppComponent.ngAfterViewInit (http://localhost:4200/main.bundle.js:79:20)
我也尝试过以下方式导入
import {Handsontable} from 'handsontable';
它给了我以下错误
Uncaught Error: Cannot find module 'numbro' at newRequire (handsontable.js:53) [] at :8000/vendor.bundle.js:102461:16 [ ] at Object.23.cellTypes (handsontable.js:4439) [ ] at newRequire (handsontable.js:58) [ ]
我已经尝试过https://github.com/handsontable/handsontable/issues/3627的所有方法
目前,HandsOnTable正式不支持Angular2。请在此处参考论坛参考。计划今年第一季度。您可以在此处对该功能进行投票
因此,您将必须像这样直接将handsontable js&css文件用于angular2应用中-
步骤1:在Index.html中,添加以下两行:
请注意 -我正在使用angular2最终版本2.0.0