gpt4 book ai didi

javascript - 语法错误 : Token 'mod' is unexpected, 期望 [:] at column 12 of the expression [partials/{{mod}}. html] 从 [mod}}.html] 开始

转载 作者:可可西里 更新时间:2023-11-01 01:22:33 29 4
gpt4 key购买 nike

我正在尝试做简单的思考。在循环中使用 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>

所以我看不出我做错了什么

最佳答案

ng-includesrc 需要一个表达式,而不是一个字符串:

<div ng-include src="'partials/' + mod + '.html'"></div>

关于javascript - 语法错误 : Token 'mod' is unexpected, 期望 [:] at column 12 of the expression [partials/{{mod}}. html] 从 [mod}}.html] 开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17533973/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com