繁体   English   中英

jQuery函数angular2 / 5

[英]Jquery function angular2/5

我想在我的angular5项目中使用jquery库

问题:要启用分页

使用npm安装jQuery

库: http//pagination.js.org/

但是我已经将jquerypagnation js添加到我的项目中

angular-cli.json

  "scripts": [
   "../src/assets/script/custom.js",  //a custom script
    "../src/assets/script/paginathing.js" //the pagination script
  ],

打字

declare var customs:any;
declare var paginathing:any;

app.component.ts

    import { Component, OnInit } from '@angular/core';

import * as customs from 'customs';
import * as paginate from 'paginathing';
import * as $ from 'jquery'
// declare var paginathing:any;
@Component({
  selector: 'app-root',
  templateUrl: './appeal.component.html',
  styleUrls: ['./appeal.component.css']
})
export class AppealComponent implements OnInit {
  data: any;
  p: number = 1;
  constructor(){

  }

  ngOnInit() {


    $('.table tbody').paginathing({ //paginathing
      perPage: 4,
    })

  }



}

错误

$(...).paginathing is not a function
at AppealComponent.ngOnInit

我建议您使用Angular的功能而不是通过导入jQuery创建分页。 这样做真是个坏主意.. 在这里继续阅读@Phil解释

检查这个例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM