簡體   English   中英

綁定屬性值時出錯-角度包含和指令

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM