0

我是 angularjs 的新手,正在尝试编写指令。我的指令代码是

Directives.directive("roleTemplate", function(){
    return {
        restrict : 'EA',
        template : '<div class="box span6">'+
                        '<div class="box-header">'+
                            '<h2 class="custom"><i class="fa-icon-group" style="opacity:.7"></i><span class="break"></span>titile</h2>'+
                        '</div>'+
                        '<div class="box-content">'+
                            '<p><strong>As a team leader you are likely to...</strong></p>'+
                            '<ul>'+
                                '<li>test</li>'+
                            '</ul>'+
                        '</div>'+
                    '</div>',   
        replace : true,
        link : function(scope,element,attr){

        }
    };
});

当我添加时它工作正常

<div role-template></div>

但是当我将 ng-repeat 添加到模板代码时,它变成了

<div class="box span6" ng-repeat = "ob in atWorkObjectsArray">

Firfox 消息弹出窗口说

A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger, or let the script continue.

Script: http://localhost:8080/tm-webapp/resources/lib/angular.js:4678

我的问题是这可能是 ng-repeat 的问题,我可以在模板中使用它吗?

上传数据:

$scope.atWorkObjectsArray = [$scope.workEffectivenessObj,$scope.workTeamLeadObj];

在哪里

$scope.workEffectivenessObj = {"title":"Effectiveness", "array":userProperties.atWorkProblmSolving};

$scope.workTeamLeadObj = {"title":"Team Lead", "array":userProperties.atWorkTeamLead};

atWorkProblmSolving并且atWorkTeamLead是 javascripts 数组。

如果我在视图(html)中使用相同的模板代码,它工作正常。

4

1 回答 1

0

如果没有 atWorkObjectsArray,就很难看出哪里出了问题。但是你可以在指令中使用 ng-repeats。这是我可以用作指南的简单示例。

    template: '<div> <div ng-repeat="d in data">{{d}}</div></div>'

http://jsfiddle.net/vhC7X/

于 2013-08-29T08:17:32.513 回答