【问题标题】:Angular template variables not resolved in PhpStormAngular 模板变量未在 PhpStorm 中解析
【发布时间】:2020-02-04 17:20:33
【问题描述】:

我在 PhpStorm 中有一个 Angular 7 应用程序,通过 ctrl 单击模板进行解析适用于所有内容(Angular 特定属性,如 *ngIf、自定义组件标签或管道),但不适用于局部变量。

例如我有这个组件:

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

Component({
    selector: 'test-component',
    templateUrl: './test.component.html'
});
export class TestComponent {
    public list: string[];
}

使用此模板:

<ng-container *ngFor="let x of list">
    Hello {{x}}
</ng-container>

我可以ctrl点击导入的模块@angular/core去定义,ctrl点击*ngFor跳转到声明文件,点击{{x}}跳转到*ngFor/let等。但我不能点击list 跳转到.ts 文件中的声明。它也以红色呈现,并带有注释“未解析的变量或类型”。

我已经安装了 node_modules,它是项目的一部分,没有被排除在外。除模板变量外,所有 Typescript 和 Angular 自动完成等都有效。

PhpStorm 是 2019.2.3,Angular 插件已安装和配置。我已经尝试过使缓存无效、重新索引和重新启动。

【问题讨论】:

  • 使用您的(和类似的)示例对我来说效果很好。如果缓存失效后问题仍然存在(File > Invalidate caches, Invalidate and restart),请创建支持票,提供一个示例项目,该问题可以通过 +idea.log 重现
  • 谢谢@lena,在此期间我想通了(见下文)。

标签: angular phpstorm


【解决方案1】:

原来我为 PHP 分配了 .html 扩展名(因为我在项目中有很多遗留文件)。奇怪的是,除了模板变量之外,所有 Angular 完成机制都有效。在文件类型区域中将 .html 分配给 Angular 解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-03
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多