Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commenting (out) code in Angular2 TypeScript

I have the following Angular2 TypeScript code with a section commented out as per 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, once the TypeScript compiles to Javascript I get the following output to my web browser:

Browser image

I've searched the API docs and can't find an entry specifying the syntax for this quite basic feature. Anyone know how you do multi-line comments in TypeScript?

like image 427
Peter David Carter Avatar asked Apr 04 '16 07:04

Peter David Carter


People also ask

How do you comment something out in code?

You can comment out one or more lines of code in any C/C++ editor view. The leading characters // are added to the beginning of each line when commenting one or more lines of code. You can also block comment multiple lines of code using the characters /* */ .

How do you comment out angular codes?

You can use HTML comment syntax instead <! -- --> . The HTML commented out this way still is added to the DOM but only as comment.

How do you comment in angular 12?

Single line Comment in Typescript It is used to give a short description of the line of code. You can include a comment in a separate line or inline. Single Line Comments always starts with // symbol. Following is an example of Single Line Comment.


2 Answers

/* */ is typescript comment delimiter

They don't work inside a string literal.

You can use HTML comment syntax instead <!-- -->.

@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>
})

The HTML commented out this way still is added to the DOM but only as comment.

like image 118
Günter Zöchbauer Avatar answered Oct 18 '22 03:10

Günter Zöchbauer


Does not seem to work, though, because it only hides the HTML, while still trying to execute the typescript code inside the commented section.

like image 23
hannodb Avatar answered Oct 18 '22 03:10

hannodb