2

I tried to import NgForm in angular with the following import

import { NgForm } from '@angular/forms/src/directives/ng_form';

It searches for node modules folder in src/app which is why it returns an error. The node modules folder is 2 levels up from the app folder.

However when I try the following path

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

It works no problem. Why is this? I use vscode, so the first path is the default way that VScode auto-imported NgForm.

1
  • It is a TypeScript issue It is still happening in v2.6.2 but it looks like we shouldn't have to wait long for this to get fixed. github.com/Microsoft/TypeScript/pull/20049 Commented Dec 20, 2017 at 3:42

1 Answer 1

1

It is due to Angular v4 no longer support deep imports like this.

import { NgForm } from '@angular/forms/src/directives/ng_form';
Sign up to request clarification or add additional context in comments.

5 Comments

Do you know how I can auto-import the correct way in VScode editor?
it will show a bulb icon in yello when you hove over NgForm. you can click that
did that help you?
I do not any see lightbulb when I do that. I want the auto import to not do a deep import. Just do @angular/core
Sorry I installed all of those packages and it is still same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.