简体   繁体   中英

How to get Visual Studio to import javascript modules using alias instead of relative path?

I'm trying out Angular2 with Typescript in Visual Studios with Resharper. It appears that when classes are imported through the import hint, the relative path to the libraries are used.

For example, I haven't imported Validators class, I get this hint and went ahead to import it. 在此输入图像描述

I will get this import statement at the top of my code:

import {Validators} from "../../../node_modules/@angular/forms/src/validators";

How can I get Visual Studio to import modules and scripts through the alias name instead of relative path? Such that it will look like so:

import { Validators } from '@angular/common';

Visual Studio 15.5.2 with Resharper 2017.2.2 finds the correct reference for me.

在此输入图像描述

Try importing from @angular/forms

import { Validators } from '@angular/forms';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM