0

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":""} 
5
  • How does it look data coming from server? Commented Jun 23, 2014 at 12:07
  • With service and http.get. Then I put the Data I need to betTypes Commented Jun 23, 2014 at 12:17
  • What if you just ng-include the file without getBetTypeById(id). Does it work then? Commented Jun 23, 2014 at 12:29
  • Do you mean just to put the src without the function? Hard coded? Commented Jun 23, 2014 at 12:33
  • Can you post some sample data you receive? Commented Jun 23, 2014 at 12:33

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.