I am trying to include some directives dynamically according some data I receive from my server. I have asked this so before and now the directive is uploaded, but there is some error I see in the console, here is what I get: Syntax Error: Token 'type' is unexpected, expecting [:] at column 3 of the expression [{{type}}] starting at [type}}].
Here is the main page html:
<div ng-repeat="type in bet.bet_types">
<div ng-include src="getBetTypeById(type.id)"></div>
</div>
Here is the getBetTypeById(id)
function from the scope:
$scope.getBetTypeById = function(id)
{
switch(id)
{
case 1:
return '/views/partials/1.html';
break;
...
Here is the 1.html:
<test-test bettype={{type}}></test-test>
here is the tets-test directive:
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');
}
};
});
And here is the bettaype_soccer_winner.html
:
<h2>test</h2>
There is no alert after the directives are loaded, and the above error is seen in the console.
What is wrong with what I do? I believe that the issue is related to the line of code <test-test bettype={{type}}></test-test>
Here is a sample of an type:
{"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":""}
You should be passing a model into the directive. Not the expression. Remove curly brackets, that should do the trick.
<test-test bettype="type"></test-test>
cheers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.