Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 创建一个不重复的列表_Angularjs_Angularjs Directive_Angularjs Scope_Angularjs Ng Repeat - Fatal编程技术网

Angularjs 创建一个不重复的列表

Angularjs 创建一个不重复的列表,angularjs,angularjs-directive,angularjs-scope,angularjs-ng-repeat,Angularjs,Angularjs Directive,Angularjs Scope,Angularjs Ng Repeat,我想创建一个指令,它不需要ngRepeat,因为指令上有一些附加功能,这对ngRrepeat不起作用 这是我对ng的指示,请重复: <div> <ul> <li ng-repeat="item in items track by $index" ng-class="attrs.itemTheme" data-item="{{ item[attrs.itemId]}}"> <div ng-include="attrs.tpl">

我想创建一个指令,它不需要ngRepeat,因为指令上有一些附加功能,这对ngRrepeat不起作用

这是我对ng的指示,请重复:

<div>
<ul>
    <li ng-repeat="item in items track by $index" ng-class="attrs.itemTheme" data-item="{{ item[attrs.itemId]}}">
        <div ng-include="attrs.tpl"></div>
    </li>
</ul>
</div>

attrs.tpl,nt dimension是另一个指令,它使用ngRepeat中的items值:

<script type="text/ng-template" id="dimension-item-tpl.html">
    <div nt-dimension x-attrs="item"></div>
</script>
<div> 
   <ul></ul>
</div>

无需重复:

<script type="text/ng-template" id="dimension-item-tpl.html">
    <div nt-dimension x-attrs="item"></div>
</script>
<div> 
   <ul></ul>
</div>

    请给我举个例子,我不再为此挣扎了

    代码示例:

    不起作用示例:

    必须编译并附加ngIncluded模板,但问题是,它只编译最后一个模板,因为摘要周期太慢了

    var el = jqElm.find('ul');
    scope.attrs.list.forEach(function (vl) {
        var tmp = 
            '<li class="' + attrs.itemTheme + '" data-item="' + vl.id + '">' +
                '<div ng-include="\'' + attrs.itemTpl + '\'"></div>' +
                    '</li>';
    
        scope.item = vl; // this is to slow :(
    
        var b = $compile(tmp)(scope);
        el.append(b);
    });
    
    var el=jqElm.find('ul'); scope.attrs.list.forEach(函数(vl){ var tmp= “
  • ”+ '' + “
  • ”; scope.item=vl;//这是为了降低速度:( var b=编译(tmp)(范围); el.附加(b); });
    您需要手动为每个
    li
    创建一个自己的范围,这样每个项都有自己的数据

    var ul = jqElm.find('ul');
    
    scope.list.forEach(function (vl) {
    var li = '<li><div ng-include="\'item-tpl2.html\'"></div></li>';
    var newScope = scope.$new();
    newScope.item = vl;
    var cLi = $compile(li)(newScope);
    ul.append(cLi);
    
    var ul=jqElm.find('ul'); 范围列表forEach(功能(vl){ 变量li='
  • '; var newScope=scope.$new(); newScope.item=vl; var cLi=$compile(li)(新闻范围); 附加(cLi);
    看看这个帖子错误:[$interpolate:interr]不能插入:{{generatedList}这将如何工作,在这里我仍然需要ngRepeatok,来编译列表,但现在我对ng include的用法有一个问题,如何在这里传递项目???真的,在我之前没有人想这样做???谢谢,这真的太棒了。thx,如果我遇到你,第一轮由我来做