将Jquery导入Angular 4时出错

时间:2017-12-07 05:53:00

标签: angular

我试图将bootstrap导入到我的angular4项目中。首先,我试图导入jQuery。 我编码如下所示。

let autocompleteController = GMSAutocompleteViewController()
autocompleteController.tintColor = .white

我100%确定我导入了js和css文件。

之后,我可以做到

npm install jquery --save
npm install --save-dev @types/jquery

然而,当我做服务器时。

出现了数百个错误

控制台输出:

$("asc").show()

任何人都可以知道这可能是什么问题?我花了很多时间在"/Users/Eva/Desktop/auction/node_modules/@types/jquery/index.d.ts (6514,45): Duplicate identifier 'never'" index.d.ts中找到一行代码:

@types/jQuery  和我的// TypeScript Version: 2.3。这是问题吗?如果是,如何更改为TypeScript version is 2.62.3之后的任何tsc都无法使用jQuery?

1 个答案:

答案 0 :(得分:0)

如果您使用的是Cli,可以尝试以下步骤

This is without using typing in the below link you can find with types as well

更新Angular-cli.json

  "scripts": ["../node_modules/jquery/dist/jquery.js"
  ]

<强>组件

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

declare var $ :any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
}

然后你可以使用ngAfterViewInit

中的jquery

link

中的工作示例

更多相同的https://rahulrsingh09.github.io/AngularConcepts/faq

相关问题