在Angular2 TypeScript中注释(out)代码 [英] Commenting (out) code in Angular2 TypeScript

查看:324
本文介绍了在Angular2 TypeScript中注释(out)代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Angular2 TypeScript代码,其中一节按照Javascript惯例注释掉:

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

但是,一旦TypeScript编译成Javascript,我就会得到以下输出到我的网页浏览器:

However, once the TypeScript compiles to Javascript I get the following output to my web browser:

我搜索过API文档但找不到指定syn的条目对这个非常基本的功能征税。有人知道你如何在TypeScript中进行多行注释吗?

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?

推荐答案

/ * * / 是打字稿评论分隔符

它们在字符串文字中不起作用。

They don't work inside a string literal.

你可以请使用HTML注释语法<! - - >

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

以这种方式注释掉的HTML仍然会添加到DOM中,但仅作为注释。

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

这篇关于在Angular2 TypeScript中注释(out)代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆