Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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
Javascript 为每个元素应用自定义角度过滤器_Javascript_Angularjs - Fatal编程技术网

Javascript 为每个元素应用自定义角度过滤器

Javascript 为每个元素应用自定义角度过滤器,javascript,angularjs,Javascript,Angularjs,查看,我运行了这个自定义过滤器来修剪文本,剪切最后3个字符,如果输入超出限制,则追加… app.html <div ng-controller="MyCtrl"> <table> <thead> <th>Name</th> </thead> <tbody> <tr ng-repeat="s in

查看,我运行了这个自定义过滤器来修剪文本,剪切最后3个字符,如果输入超出限制,则追加

app.html

  <div ng-controller="MyCtrl">
       <table>
        <thead>
            <th>Name</th>
        </thead>
        <tbody>
            <tr ng-repeat="s in strs | customTrim:2">
                <td>{{s}}</td>
            </tr>
        </tbody>
    </table>
然而,
strs
的长度,而不是单个
s
,似乎正在打印出来

如何将数组中的每个项传递到我的
customFilter

控制台

limitToFilter('ABCDEF', 2) A 
input: ["HEY THERE", "me"] input.length 2 limit: 2 
input: ["HEY THERE", "me"] input.length 2 limit: 2 

您应该对字符串而不是数组使用筛选器:

<tr ng-repeat="s in strs">
    <td>{{s | customTrim:2}}</td>
</tr>

{{s | customTrim:2}}

您应该在字符串上使用过滤器,而不是在数组上使用过滤器:

<tr ng-repeat="s in strs">
    <td>{{s | customTrim:2}}</td>
</tr>

{{s | customTrim:2}}

您应该在字符串上使用过滤器,而不是在数组上使用过滤器:

<tr ng-repeat="s in strs">
    <td>{{s | customTrim:2}}</td>
</tr>

{{s | customTrim:2}}

您应该在字符串上使用过滤器,而不是在数组上使用过滤器:

<tr ng-repeat="s in strs">
    <td>{{s | customTrim:2}}</td>
</tr>

{{s | customTrim:2}}