首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:$(.).sortable不是角函数

TypeError:$(.).sortable不是角函数
EN

Stack Overflow用户
提问于 2018-06-21 09:51:50
回答 1查看 7.1K关注 0票数 2

我使用jquery和jquery在我添加的角项目中执行拖放功能,

Index.html:

代码语言:javascript
复制
<link href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

Component.ts:

代码语言:javascript
复制
declare var jquery:any;
declare var $ :any;

export class DropAreaComponent implements OnInit, OnDestroy {
      ngOnInit(): void {
        $("#people").sortable({
          update: function(e, ui) {
            $("#people .draggable").each(function(i, element) {
              $(element).attr("id", $(element).index("#people .draggable"));
              $(element).text($(element).text().split("Index")[0] + " " + "Index: " + " => " + $(element).attr("id"));
            });
          }
        });
}

Component.html:

代码语言:javascript
复制
<ul id="people">
    <li *ngFor="let person of people; let i = index">
      <div class="draggable" id={{i}}>
        <p> <b> {{ person.name }} </b> Index => {{i}}</p>
      </div>
      <br><br>
    </li>
  </ul>

但它显示的错误是,

代码语言:javascript
复制
ERROR TypeError: $(...).sortable is not a function

包含脚本中的以下内容,

代码语言:javascript
复制
"scripts": [
    "../node_modules/jquery/dist/jquery.js",
    "../node_modules/moment/moment.js",
    "../node_modules/bootstrap/dist/js/bootstrap.js",
    "../node_modules/hammerjs/hammer.js",
    "../node_modules/materialize-css/dist/js/materialize.js",
    "../node_modules/bootstrap-material-design/dist/js/material.js",
    "../node_modules/bootstrap-material-design/dist/js/ripples.min.js",
    "../node_modules/arrive/src/arrive.js",
    "../node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js",
    "../node_modules/bootstrap-notify/bootstrap-notify.js",
    "../node_modules/chartist/dist/chartist.js",
    "../node_modules/bootstrap-material-datetimepicker/js/bootstrap-material-datetimepicker.js"
],

当我包括在index.html中时,角剪贴画中的脚本有什么问题吗?请帮我解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-21 09:59:03

遗漏: jquery-ui.min.js

  • 运行npm安装jquery dist
  • 在脚本中添加路径(在jquery包含行之后添加) ../node_modules/jquery-ui-dist/jquery-ui.min.js

从index.html中删除以下脚本

代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50965549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档