Я пробовал количество методов, опубликованных в StackOverflow, чтобы использовать jquery-ui в угловом 6 компоненте, но ни один из них не работал.Например,
Я запустил npm установить jquery jquery-ui для установки jquery и jquery-ui.
Включеноследующие в angular.json
"scripts": ["node_modules / jquery / dist / jquery.js", "node_modules / jquery-ui-dist / jquery-ui.js",
Ошибка выглядит следующим образом:
AppComponent_Host.ngfactory.js [sm]:1ERROR TypeError: jquery__WEBPACK_IMPORTED_MODULE_1__(...).slider is not a function
at AppComponent.push../src/app/app.component.ts.AppComponent.ngAfterContentInit (http:||localhost:4200/main.js:154:56)
at callProviderLifecycles (http:||localhost:4200/vendor.js:42663:18)
at callElementProvidersLifecycles (http:||localhost:4200/vendor.js:42644:13)
at callLifecycleHooksChildrenFirst (http:||localhost:4200/vendor.js:42634:29)
at checkAndUpdateView (http:||localhost:4200/vendor.js:43565:5)
at callWithDebugContext (http:||localhost:4200/vendor.js:44454:25)
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (http:||localhost:4200/vendor.js:44132:12)
at ViewRef_.push../node_modules/@angular/core/fesm5/core.js.ViewRef_.detectChanges (http:||localhost:4200/vendor.js:41948:22)
at http:||localhost:4200/vendor.js:37684:63
at Array.forEach (native)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Car Dealer</title>
</head>
<body>
<app-root></app-root>
</body>
</html>
app.component.html
<div id="slider">
</div>
app.component.ts
import { Component, AfterContentInit } from '@angular/core';
import * as $ from 'jquery';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterContentInit {
title = 'MDK';
ngAfterContentInit() {
$( "#slider" ).slider({
range: true,
values: [ 17, 67 ]
});
}
}
В другом посте предлагается, чтобы я не использовал angular.JSON Angular 6 вообще, но используйте index.html для включения скриптов, но это также не сработало.
Я включил следующее в index.html, но даже тогда появилась та же ошибка
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>