Comment Code in Angular2 TypeScript

I have the following Angular2 TypeScript code with a section marked according to the Javascript convention:

@Component({ selector: 'my-app', template: `<h1>{{title}}</h1> <h2>{{lene.name}}</h2> <div><label>id: </label>{{lene.id}}</div> /*<div> <label>name: </label> <input [(ngModel)]="lene.name" placeholder="name"> </div>*/` <div><label>description: </label>{{lene.description}}</div> }) 

However, as soon as TypeScript is compiled into Javascript, I get the following output in my web browser:

Browser image

I searched for API docs and cannot find an entry defining the syntax of this rather simple function. Does anyone know how you make multi-line comments in TypeScript?

+6
source share
2 answers

/* */ typescript comment delimiter

They do not work inside a string literal.

Instead of comment syntax, you can use comment syntax <<21>.

 @Component({ selector: 'my-app', template: `<h1>{{title}}</h1> <h2>{{lene.name}}</h2> <div><label>id: </label>{{lene.id}}</div> <!-- <div> <label>name: </label> <input [(ngModel)]="lene.name" placeholder="name"> </div> -->' <div><label>description: </label>{{lene.description}}</div> }) 

HTML commented this way is still added to the DOM, but only as a comment.

+14
source

If you are in a template, use the HTML comment <!-- ... --> :

 @Component({ selector: 'my-app', template: ` <h1>{{title}}</h1> <h2>{{lene.name}}</h2> <div><label>id: </label>{{lene.id}}</div> <!-- div> <label>name: </label> <input [(ngModel)]="lene.name" placeholder="name"> </div--> <div><label>description: </label>{{lene.description}}</div> ` }) 
+3
source

All Articles