Visual Studio -为HTML模板和语法高亮显示使用自定义脚本标签类型
Visual Studio - Using Custom Script Tag Type for HTML Templates and Syntax Highlighting
我使用Visual Studio 2012来编辑HTML和JavaScript。我通过在内联脚本标签中使用部分视图来添加模板(见下面的代码)。AngularJS,一个Javascript框架,要求类型为text/ng-template
,但是Visual Studio不能识别它为HTML,也不提供语法高亮显示。如果类型是text/HTML
,一切工作正常。
我的问题:在Visual Studio 2012中是否有一种方法可以将自定义脚本类型关联到HTML语法高亮显示?解决方案不应该只适用于text/ng-template
,但对于其他类型,你想要HTML语法高亮。
<script type="text/ng-template" id="filterOrder.html">
<!-- Sidebar comment-->
Search: <input ng-model="query"/>
Sort by:
<select ng-model="orderProp">
<option value="name">Alphabetical</option>
<option value="age">Newest</option>
</select>
<div id="status">Current filter: {{query}}</div>
</script>
我无法说服VS2012突出显示text/ng-template
脚本,所以我使用text/template
并在我的启动代码中添加了一点。这将枚举您想要的任何类型的脚本标签,并将它们添加到$templateCache中。
var app = angular.module('app', [...]);
app.run(function ($templateCache) {
// <script type="text/ng-template"> ... is preferred, but VS 2012 doesn't give intellisense there
angular.element('script[type="text/template"]').each(function(idx, el) {
$templateCache.put(el.id, el.innerHTML);
});
});
text/template
在我的设置中触发HTML智能感知
<script type="text/template" id="home.html">
<h3>HTML intellisense, code completion, and formatting!</h3>
</script>
我是这样做的:
@using (Html.NgTemplate("Text"))
{
<div class="control-group">
<label class="control-label">{{item.label}}</label>
<div class="controls">
<input type="text" class="input-xxlarge" ng-model="item.value">
</div>
</div>
}
Visual studio不知道它是一个脚本标签,并给我完整的自动完成。
使用Trey Mack的回答,我无法在class=" "中获得css类的列表。
然而,通过将标签类型更改为text/html并修改app.run,我得到了语法和CSS类名列表。
<script type="text/html" id="home.html">
<h3>HTML intellisense, code completion, and formatting!</h3>
</script>
然后……
var app = angular.module('app', [...]);
app.run(function ($templateCache) {
// <script type="text/ng-template"> ... is preferred, but VS 2012 doesn't give intellisense there
angular.element('script[type="text/html"]').each(function(idx, el) {
$templateCache.put(el.id, el.innerHTML);
});
});
注:我使用VS 2015
相关文章:
- 如何在用户按下F5键或单击浏览器时显示自定义的fancybox's后退/关闭按钮
- 如何在html中以角度显示自定义指令的作用域
- 使用Plaid Link显示自定义用户名和密码模式对话框
- 根据屏幕分辨率显示自定义背景图像
- 登录时显示自定义错误消息
- 如何在具有多边形的同一地图上显示自定义标记
- 如何在javascript中使画布显示自定义图像作为背景
- Chrome扩展-在全屏视频顶部显示自定义通知/弹出窗口(HTML元素)
- 根据 IP 向 Web 访问者显示自定义消息
- 如何使用人力车库在折线图上显示自定义工具提示
- 无法显示自定义对话框
- 使用相对文件路径在 Google 地图中显示自定义标记
- 如何在移动浏览器的屏幕顶部显示自定义警报
- Wavesurfer.js:如何显示自定义标记
- 在谷歌地图中按类型显示自定义图像标记图标
- 如何在检测到浏览器关闭事件时显示自定义弹出窗口
- 通过jQuery在Html.ValidationMessageFor中显示自定义错误
- 自定义HTML5表单验证最初未显示自定义错误
- 在剑道装载指示器上显示自定义文本
- 如何在jqGrid中隐藏和显示自定义按钮通过使用"reccount”;