[英]Error with binding an attribute value - angular include and directives
我试图根据从服务器接收到的某些数据动态地包含一些指令。 我也问过这个所以才和现在的指令上传,但有一些错误我在控制台中看到,这里是我得到: Syntax Error: Token 'type' is unexpected, expecting [:] at column 3 of the expression [{{type}}] starting at [type}}].
这是主页html:
<div ng-repeat="type in bet.bet_types">
<div ng-include src="getBetTypeById(type.id)"></div>
</div>
这是作用getBetTypeById(id)
函数:
$scope.getBetTypeById = function(id)
{
switch(id)
{
case 1:
return '/views/partials/1.html';
break;
...
这是1.html:
<test-test bettype={{type}}></test-test>
这是tets-test指令:
var app = angular.module('soccerWinner', []);
app.directive('testTest', function()
{
return {
restrict: 'E',
replace: true,
scope:
{
bettype: '='
},
templateUrl: '/views/partials/directives/bettaype_soccer_winner.html',
controller: function()
{
alert('dfd');
}
};
});
这是bettaype_soccer_winner.html
:
<h2>test</h2>
加载指令后没有警报,并且在控制台中看到上述错误。
我的工作有什么问题? 我认为问题与代码行<test-test bettype={{type}}></test-test>
这是类型的示例:
{"id":1,"name":"Winning Team or Tie","description":"Choose the winnig team.","schema":"{\n\t \t'winnerId': 'integer',\n 'options:' []\n\t }","created_at":"2014-06-22 13:13:07","updated_at":"2014-06-22 13:13:07","pivot":{"bet_id":1,"bet_type_id":1},"userBet":""}
您应该将模型传递给指令。 不是表达。 除去大括号,应该可以解决问题。
<test-test bettype="type"></test-test>
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.