出现错误 - 找不到名称“angular" [英] Getting Error - Cannot find name 'angular'

查看:30
本文介绍了出现错误 - 找不到名称“angular"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 TypeScript 编写 AngularJS 应用程序.我有这个简单的模块命令:

(() => {有角的.module('app', []);})();

当我运行 tsc app.ts 时,我得到了这个:app.ts(2,5):错误 TS2304:找不到名称 'angular'.>

我是否需要在 app.ts 中包含一些内容以使 tsc 理解 angular?

问候,

解决方案

你可以简单地告诉编译器不要担心,告诉它你对 angular 了如指掌":

声明var angular: any;

要获得所有好的工具和类型检查,您需要引入 Angular 类型定义所以编译器知道什么是可用的.

如果您使用 Visual Studio 或您喜欢的 IDE 的各种其他方法,则可以通过 NuGet 获得类型定义.

I'm starting writing AngularJS app using TypeScript. I have this simple module command:

(() => {
    angular
        .module('app', []);
})();

When I run tsc app.ts, I got this: app.ts(2,5): error TS2304: Cannot find name 'angular'.

Do I need to include something to app.ts to make tsc understand the angular?

Regards,

解决方案

You could simplistically tell the compiler to stop worrying by telling it that "you know all about angular":

declare var angular: any;

To get all the good tooling and type checking, you need to pull in the Angular type definition so the compiler knows what is available.

The type definitions are available via NuGet if you are using Visual Studio or various other methods for your favourite IDE.

这篇关于出现错误 - 找不到名称“angular"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆