语法错误:令牌'mod'是意外的,期望在[mod}}开始的表达式[partials / {{mod}}。html]第12列的[:]。html]

时间:2013-07-08 18:57:16

标签: javascript angularjs

我试图做简单的思考。 在循环中使用ng-include将多个html页面包含在渲染页面中。

<div ng-controller="pageCTRL">
 <div ng-repeat="mod in modules">
  <div ng-include src='partials/{{mod}}.html'></div>
 </div>
</div>

$scope.modules = ["mod_nav","mod_feature","mod_footer"];

但我得到的就是这个。

Error: Syntax Error: Token 'mod' is unexpected, expecting [:] at column 12 of the expression [partials/{{mod}}.html] starting at [mod}}.html].
at Error (<anonymous>)
at throwError (angular.js:6066:11)
at consume (angular.js:6104:7)
at object (angular.js:6394:9)
at primary (angular.js:6278:17)
at unary (angular.js:6265:14)
at multiplicative (angular.js:6251:39)
at additive (angular.js:6239:16)
at relational (angular.js:6230:16)
at equality (angular.js:6221:16) <div ng-include="" src="partials/{{mod}}.html"> 

你有解决方法吗?

呈现的代码如下所示:

  <div ng-include="" src="partials/mod_nav.html"></div>

所以我不知道自己做错了什么

1 个答案:

答案 0 :(得分:30)

ng-include的{​​{1}}需要一个表达式,而不是字符串:

src