【问题标题】:ng-show > 10 throws syntax error (VS browser link)ng-show > 10 引发语法错误(VS 浏览器链接)
【发布时间】:2024-04-18 16:40:05
【问题描述】:

我有一个表格单元格,它显示是否有超过 10 条记录。我的分页的一部分。

<td ng-show="totalRecords>10" colspan="5">
    <ul uib-pagination style="margin:0;" total-items="totalRecords" ng-model="currentPage" ng-change="pageChanged()"></ul>
</td>

非常简单。但这是疯狂的 - 它在 Chrome 中引发以下错误:

Uncaught Error: Syntax error, unrecognized expression: td[ng-show='totalRecords @ browserLink:37 
bc.error @ browserLink:37
bh @ browserLink:37
bp @ browserLink:37
...etc

我会注意到 $scope.totalRecords 在控制器中设置为零 (0)。将其设置为其他值不会改变任何内容。控制器中的其他一切都运行良好。

以下场景不会抛出任何错误:

<td ng-show="totalRecords=10" colspan="5">...</td>
<td ng-show="totalRecords<10" colspan="5">...</td>
<td ng-show="totalRecords>9" colspan="5">...</td>
<td ng-show="totalRecords>=11" colspan="5">...</td>
<td ng-show="totalRecords" colspan="5">...</td>

有人猜到为什么吗?

【问题讨论】:

  • 试试 ng-if 而不是 ng-show?
  • 您使用的是 Microsoft Visual Studio 2013 或更高版本吗?

标签: angularjs visual-studio syntax-error browser-link


【解决方案1】:

问题在于 Visual Studio 的“浏览器链接”功能,它可能会导致 AngularJS 出现问题。根据我对您遇到的错误所做的一些研究,似乎人们建议禁用 Visual Studio 中的浏览器链接功能。

http://connect.microsoft.com/VisualStudio/feedbackdetail/view/814546/browserlink-throws-an-exception-when-using-angularjs-and-binding-in-an-attribute-browserlink-does-not-like-in-a-html-attribute

以下链接包含对您遇到的错误的类似描述以及禁用浏览器链接功能的几种方法:

http://www.telerik.com/forums/the-new-browser-link-feature-in-vs-2013-is-causing-an-error-when-detailtable-of-hierarchy-radgrid-is-expanded

【讨论】: