Commenting (out) code in Angular2 TypeScript

余生颓废 提交于 2019-12-04 04:30:20

/* */ 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.

If you are in the 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>
  `
})

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!