Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML string inside TypeScript and JavaScript files? #2000

Closed
mohsen1 opened this issue Jan 14, 2016 · 18 comments
Closed

HTML string inside TypeScript and JavaScript files? #2000

mohsen1 opened this issue Jan 14, 2016 · 18 comments
Assignees
Labels
feature-request Request for new features or functionality typescript Typescript support issues
Milestone

Comments

@mohsen1
Copy link

mohsen1 commented Jan 14, 2016

When using Angular 2 and TypeScript I noticed that editing template strings of components in TypeScript files are not working as one expect. There is not autocomplete for tags and other usual HTML editing features.

For example

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent { }

Of course it's because the type definition has declared template as a String and no part of VSCode knows that it's an HTML string.

My proposal is to define a HTMLString type where it's basically just string but helps tooling in cases like this.

If it was possible to do this, then we can define CSSString, JavaScriptString, SCSSString and so on...

@dbaeumer dbaeumer added feature-request Request for new features or functionality typescript Typescript support issues labels Jan 15, 2016
@dbaeumer dbaeumer added this to the Backlog milestone Jan 15, 2016
@cebor
Copy link

cebor commented Jan 31, 2016

👍

@dbaeumer
Copy link
Member

dbaeumer commented Feb 1, 2016

I copied the item to the TS repository to hear their opinion: microsoft/TypeScript#6778

@sheldonbarnes
Copy link

Consider using templateUrl, and specifying a HTML file name. You can then get all the autocomplete in that HTML file. I think that is better than mixing code and HTML like Classic ASP.

Example:

https://github.com/sheldonbarnes/Angular2Learning/blob/master/app/app.customerdetailscomponent.ts

@felixfbecker
Copy link
Contributor

#1751

@MarkPieszak
Copy link

I don't know if this would help in VSCodes case, but @GregOnNet came up with a brilliant solution for adding HTML highlighting to the back-tick section here for Atom-typescript

TypeStrong/atom-typescript#948

Hoping that might help potentially add this ability to VSCode!

@dbaeumer
Copy link
Member

dbaeumer commented May 17, 2016

@aeschli please see the latest comment. With what we discussed last week can we achieve the same?

@aeschli
Copy link
Contributor

aeschli commented May 17, 2016

@dbaeumer @egamma The solution mentioned above adds the html/angular syntax highlighting directly to the TypeScript grammar. That's one of the options we discussed last week. It would be up to the TypeScript team to decide that. Alternatively we work on adding injection support: #6331.

@juliusl
Copy link
Member

juliusl commented Aug 3, 2016

In the meantime looks like this extension works pretty well:
https://marketplace.visualstudio.com/items?itemName=nwallace.language-vscode-javascript-angular2

@stefanaerts
Copy link

@dbaeumer @egamma @juliusl @aeschli
Well the color works with the extension, but the autocomplete of
-> custom html tags, in a angular2 component we call it a selector:.
template: `

          <color-pi...      

will not complete.

@MarkPieszak
Copy link

True, it doesn't autocomplete html but at least it'll help you with variables you have within that file.

Let's say you had public someString : string; in your class, when you do {{ som...(it'll show someString). Better than nothing I suppose ;)

@icenold
Copy link

icenold commented Dec 6, 2016

https://marketplace.visualstudio.com/items?itemName=natewallace.angular2-inline

@ntziolis
Copy link

Just for other people finding this thread the link above is the working one. The other extension from the same author no longer works with the current version of vscode as far as I know.

The extension does provide:

  • intellisense
  • and coloring

But sadly NO formatting. There is an open feature request for formatting, give it some love if you also wanne see it included too: natewallace/angular2-inline#6

@robhaswell
Copy link

Is it desirable to turn this into a more generic solution? What if my backtick contained some JS code for evaulating (yuck), or more likely, I'm providing some inline scripting to an Elasticsearch query?

@felixfbecker
Copy link
Contributor

#1751

@n1ru4l
Copy link

n1ru4l commented Jul 3, 2017

@robhaswell SQL would be awesome too!

@waderyan waderyan removed their assignment Jul 13, 2017
@kenchris
Copy link

This would be quite useful for hyperHTML/viperHTML and lit-html as well

https://github.com/PolymerLabs/lit-html
https://viperhtml.js.org/

@motss
Copy link

motss commented Oct 12, 2017

@mjbvz
Copy link
Collaborator

mjbvz commented Oct 12, 2017

Yes, for angular try the angular-inline extension and for lit-html, try:

lit-html


I posted more information about embedded language support in #5961 (comment) as well. To sum up, you can already write extensions and TypeScript plugins that contribute support for embedded languages. The main remaining work is to polish the experience so that you only need to install a single vscode extension to get syntax highlighting and intellisense for your template strings. This work is now being tracked by #5961

Closing this issue in favor of #5961

@mjbvz mjbvz closed this as completed Oct 12, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality typescript Typescript support issues
Projects
None yet
Development

No branches or pull requests