安装了npm install @types/jquery --save-dev 之后,使用$仍然报错

来源:2-5 开发准备

csboy2007

2017-04-26

terminal的提示错误码是

ERROR in C:/study_case/auction/src/app/app.component.ts (11,5): Cannot find name '$'.

我app.compent.ts 代码

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

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

 }

写回答

1回答

JoJo

2017-04-26

在文件最上面加///<reference path="../../node_modules/@types/jquery/index.d.ts"/>。

//szimg.mukewang.com/5900058400011cd809360286.jpg

1
1
webJ
不是很明白 为什么会出错,我在网上查了 declare var $:any; 这种方法也可以解决 , 只是不知道 为什么要多这一步, node js 版本 是最新的 cli 是1.0版本的
2017-04-28
共1条回复

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程