Man*_*gan 2 javascript jquery jquery-ui typescript angular
我正在使用jquery和jquery ui进行我添加的角度项目中的拖放功能,
Index.html:
<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>
Run Code Online (Sandbox Code Playgroud)
Component.ts:
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"));
});
}
});
}
Run Code Online (Sandbox Code Playgroud)
Component.html:
<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>
Run Code Online (Sandbox Code Playgroud)
但是它显示错误为
ERROR TypeError: $(...).sortable is not a function
Run Code Online (Sandbox Code Playgroud)
angular-cli.json在脚本中包含以下内容,
"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"
],
Run Code Online (Sandbox Code Playgroud)
当我加入时,angular-cli.json中的脚本是否存在任何问题index.html?请帮助我解决这个问题。
你失踪了:jquery-ui.min.js
运行npm install jquery-ui-dist
在脚本中添加路径(在jquery包含行之后添加)
../node_modules/jquery-ui-dist/jquery-ui.min.js
从index.html删除以下脚本
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2372 次 |
| 最近记录: |