Ich bekomme TypeError bei der Verwendung von Angular-Datatables in meinem Code.DataTable ist keine Funktion TypeError bei der Verwendung von Angular-Datatables für Angular 4
ERROR TypeError: $(...).DataTable is not a function
at angular-datatables.directive.js:38
-Code in der Richtlinie ist:
DataTableDirective.prototype.displayTable = function() {
var _this = this;
this.dtInstance = new Promise(function (resolve, reject) {
Promise.resolve(_this.dtOptions).then(function (dtOptions) {
// Using setTimeout as a "hack" to be "part" of NgZone
setTimeout(function() {
//Error in this line
var dt = $(_this.el.nativeElement).DataTable(dtOptions);
resolve(dt);
});
});
});
};
Was ist das Problem hier? Ich installierte die Bibliothek und Abhängigkeiten von:
npm install jquery --save
npm install datatables.net --save
npm install datatables.net-dt --save
npm install angular-datatables --save
npm install @types/jquery --save-dev
npm install @types/datatables.net --save-dev
Eine Idee?
UPDATE: Hier ist mein tsconfig.app.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"allowSyntheticDefaultImports": true
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
und tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"allowSyntheticDefaultImports": true,
"paths": {
"@angular/*": [
"../node_modules/@angular/*"
]
}
}
}
Überprüfen Sie Ihre tsconfig.json und seine untergeordneten Dateien (z. B. tsconfig.app.json), wenn Sie leere Typen Array ("types": []) entfernen Sie es. – omeralper
Ich hatte einen und ich entfernte ihn, aber keine Änderung. – Burak
Haben Sie alle Dateien in der angular-cli.json-Datei hinzugefügt? – omeralper