2013-07-08 12 views
16

Próbuję zrobić proste myśleć. użyj pętli ng-include w celu włączenia wielu stron html do renderowanej strony.Błąd składniowy: Token 'mod' jest nieoczekiwany, oczekując [:] w kolumnie 12 wyrażenia [partials/{{mod}}. Html] począwszy od [mod}}. 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"]; 

Ale wszystko, co mam, to jest to.

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"> 

Czy masz jakieś rozwiązanie, jak to zrobić?

renderowane kod wygląda następująco:

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

więc nie wiem, co robię źle

Odpowiedz

30

ng-include „s src spodziewa wyrażenie, a nie ciąg:

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

od ng dok: ...

Powiązane problemy