Angular - 由于运行时错误,无法使 sortablejs 工作

标签 angular ionic-framework sortablejs angular-sortablejs

我正在尝试使用此库:https://github.com/SortableJS/ngx-sortablejs

我已经安装:npm i ngx-sortablejs sortablejs --save

我的页面 HTML

<div [sortablejs]="items">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</div>

然后我将导入到我的 app/app.module.ts

import { SortablejsModule } from 'angular-sortablejs';

...

SortablejsModule.forRoot({ animation: 150 })

最后,在我的 page.module.ts 中导入模块

import { SortablejsModule } from 'angular-sortablejs';       <<==== HERE

...

@NgModule({
  imports: [
    IonicModule,
    CommonModule,
    FormsModule,
    SortablejsModule,                                <<==== AND HERE
 ...

因此应用程序编译时没有错误,但当我尝试使用组件打开页面时,出现此运行时错误:

core.js:15724 ERROR Error: Uncaught (in promise): TypeError: OriginalSortable.create is not a function
TypeError: OriginalSortable.create is not a function
    at sortablejs.directive.js:32
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
    at NgZone.push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular (core.js:17258)
    at SortablejsDirective.push../node_modules/angular-sortablejs/dist/src/sortablejs.directive.js.SortablejsDirective.ngOnInit (sortablejs.directive.js:31)
    at checkAndUpdateDirectiveInline (core.js:22099)
    at checkAndUpdateNodeInline (core.js:23363)
    at checkAndUpdateNode (core.js:23325)
    at debugCheckAndUpdateNode (core.js:23959)
    at debugCheckDirectivesFn (core.js:23919)
    at resolvePromise (zone.js:831)
    at resolvePromise (zone.js:788)
    at zone.js:892
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17290)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601)
    at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:502)
    at invokeTask (zone.js:1744)

我做错了什么吗?

最佳答案

对我来说,升级到 Angular 8 后出现错误 OriginalSortable.create is not a function

通过将 ngx-sortablejs 升级到 3.1.3,并将 sortablejs 升级到 1.10.1,错误消失了。

关于Angular - 由于运行时错误,无法使 sortablejs 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57245530/

相关文章:

angular - 使用 TypedJSON 解析 JSON (typedjson-npm)

cordova - 请求自定义页面 ionic 原生推送的许可

vue.js - 有没有办法将 Vue.Draggable 拖放区扩展到可拖动自定义标签之外?

angular - 动态更改 MatPaginatorIntl itemsPerPageLabel

javascript - 用户使用 angular6 单击后获取所有子对象 ID 的列表

javascript - 无论如何要为 ionic 范围 slider 中的圆形按钮分配默认位置?

javascript - 如何在 promise 中返回请求

javascript - SortableJS 保持不可拖动项目固定

angular - ngx-捕获 : Unable to capture <img> inside the screen capture area