Giter Site home page Giter Site logo

angular2-in-visual-studio's Introduction

Angular 2 in Visual Studio Sample Project

Introduction

This repo is a sample project that shows off Angular 2 Language Service support in Visual Studio.

Usage

Prerequisite: Visual Studio 2017 Update 5 or later

To use this project:

  • git clone https://github.com/Microsoft/angular2-in-visual-studio.git
  • cd angular2-in-visual-studio
  • npm install
  • In Visual Studio, "Open Folder" (Ctrl-Alt-Shift-O or File -> Open -> Folder...)
  • Select the cloned directory (not src)

Tour

Once the project is opened, you can observe these new behaviors

Semantic Warnings

Open src\app\app.component.ts. The Angular2 language service warns you that the InlineComponent class doesn't belong to a module:

Error about missing module

Errors in Inline Templates

Still in src\app\app.component.ts, you can try editing the inline template in InlineComponent. The project includes a syntax error:

Syntax error

Fix the syntax error by changing </spa> to </span>. You'll now see a semantic error:

Inline semantic error

Angular2 identified another mistake here - there is no method named toLower; fix this to toLowerCase. The error disappears:

Errors resolved

Navigation

Now that we've fixed the errors, let's try some navigation. Place the caret on prop1 in the inline template. Open the context menu and select "Go to Definition":

Go to Definition

This will take us to the definition of prop1 in the corresponding component:

Navigated

.ngml Files

Open src\app\app.component.ngml. This is the template file for the corresponding class AppComponent in app.component.ts. On line 5, place the caret on prop1 and invoke "Go to Definition" again:

Go to Definition from ngml

This navigates us to the prop1 declaration in app.component.ts. Note that even though the file had two classes, both with properties named prop1, we were properly navigated to the correct one:

Navigated from ngml

Completions

In both inline templates and ngml files, we'll get completion lists.

Open src\app\contact\contact.component.ngml. Go to line 29 and place the caret to the right of . in contactForm.status, and press Ctrl-Space to open the completion list:

Completions in ngml

Visual Studio will display all the members of the contactForm. You can also see completions in NGML template positions. Place the caret on line 23 after div, and press Ctrl-Space to open the completion list:

Template completions in ngml

Now you'll see a list of the allowed attribute names, including those specific to Angular 2's template syntax, in the completion list.

angular2-in-visual-studio's People

Contributors

microsoftopensource avatar msftgits avatar ryancavanaugh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular2-in-visual-studio's Issues

New behaviour not visible if npm install from VS

Not sure if this is the correct place to make a note of this, as if its an issue its a VS issue. I didn't follow the instructions to the letter but this might indicate a potential issue?

Rather than opening the cloned folded after npm install I npm installed from the package manager console after having opened the cloned folder. Then opening app/app.component.ts. This meant that I didn't get any of the semantic warning mentioned. Closing visual studio after this and reopening, did show the semantic warnings.

How to enable this in an existing angular-cli application (within an ASP.NET MVC app)?

I added the devDependency @angular/language-service to the package.json.
In the tsconfig.json, I added
"plugins": [
{ "name": "@angular/language-service" }
]
Are there any other things to do? Could not find further hints in this demo project.

Also the use of the ngml extension is not fine.
I assume you find the corresponding component just by filename?
So why not support all .html files which have a corresponding .ts file?

SSR doesn't work

Server Side rendering in the example doesn't work! In the iis there is not file. Is the publishing never tested?

NGML Bug

I am considering moving whole team to VS instead of VSCode. I tested converting one of my components to .ngml and then enabling language service in tsconfig. However the entire ngml now complains since it's expecting typescript and not html...
image

the errors are for every single different html element
image

I also can not follow definitions or anything.

Its really annoying that to us VS we have to change all the extensions to ngml and then too this does not work properly.

P.S. i'm using the new Angular CLI dotnet core template shipped with the dotnet cli. All TS languge service stuff works.

How does one build with ngml files?

As the title says, how do you build/serve a project with ngml files without getting this:

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.

error?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.