【问题标题】:VS Code - Angular 1/TypeScript - "angular" is not recognized when removing /// referenceVS Code - Angular 1/TypeScript - 删除 /// 参考时无法识别“角度”
【发布时间】:2016-06-20 15:56:53
【问题描述】:

我决定使用 TypeScript 对 Angular 的种子项目进行一些试验。 根据vs code docs(见第二个标题),我可以将/// 引用放在我的.ts 文件顶部,如果我有正确的tsconfig.json 文件,Visual Studio Code 仍然应该给我适当的智能。好吧,我愿意,除非我放置 reference 东西,否则我的 angular 变量不会被识别。

这是我正在测试的link to the project。 请参阅src/client/home/home.ts 文件。

PS:运行 gulp 不会成功,因为这仍在进行中。

【问题讨论】:

  • 我不认为你可以将 Angular 1 作为模块导入,因为它们没有被声明为模块。
  • 您可以使用类型定义文件。查看src/client/types/libs 文件夹
  • 你试过import * as angular from './src/client/types/libs/angular/angular'来获取你的角度变量吗?
  • 不,但我不应该这样做。 VS Code 应该自己知道这个变量。
  • 我不认为是,据我所知,它只知道您何时导入或使用 /// 引用。

标签: angularjs typescript visual-studio-code


【解决方案1】:

您需要从文件中实际导出各个“角度模块”,然后将它们导入到您的主 app.js 文件中。当您将它们作为模块依赖项导入 Ngular 时,只需在末尾添加 .name 即可。 (返回它的实际字符串名称)

MyModule.name // after being imported to master app.js file


// when exporting, export the entire module not just the class controller

var homeModule = angular
    .module('app.home')
    .directive('home', homeDirective);

export = homeModule;

【讨论】:

  • 问题不在于模块,而是在删除 /// reference 事物时无法识别 angular 变量。也不会有主 app.js 文件,因为我将使用 requirejs 按需加载文件。但这无关紧要。我不想运行这个项目。只需在 VSC 中打开项目,您就会看到 angular 变量带有红色下划线。
【解决方案2】:

嗯,我愿意,除非我放置参考物,否则我的角度变量不会被识别。

快速浏览了一下。这个https://github.com/DmitryEfimenko/ng-boilerplate/pull/3 应该修复它。基本上是/ 而不是\\

【讨论】:

    猜你喜欢
    • 2016-02-25
    • 1970-01-01
    • 2019-04-22
    • 2021-08-26
    • 2020-09-08
    • 1970-01-01
    • 2022-10-05
    • 2020-08-02
    • 2018-12-31
    相关资源
    最近更新 更多