在ng-repeat的每次迭代中执行脚本/功能 [英] Execute script/function on each iteration of ng-repeat

查看:61
本文介绍了在ng-repeat的每次迭代中执行脚本/功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样的元素上使用ng-repeat:

I am using ng-repeat on an element like this:

<div ng-repeat="aSize in BC.aOutputSizesArr" style="width:{{aSize}}px; height:{{aSize}}px;">
    {{aSize}}
    <canvas/>
    <script>alert({{aSize}})</script>
</div>

所以基本上在每次重复中,我都需要基于aSize的值绘制到画布上,是否有可能在ng-repeat的每次迭代中执行一个函数?我尝试将script标记放入其中,但不起作用.

So basically on every repeat, i need to draw to the canvas based on the value of aSize, is it possible to execute a function on every iteration of ng-repeat? I tried putting that script tag in there, but it doesnt work.

推荐答案

这是一个示例我的意思是使用指令.

Here's an example of what I mean with using a directive.

此指令:

angular.module('directives', []).directive('alerter', function () {
    return {
        model: {
            size: '@'
        },
        link: function ($scope, element, attrs, controller) {
            alert(attrs.size)
        }
    };
});

使用方式:

<alerter size=10>alert 10</alerter>
<alerter size=15>alert 15</alerter>

将执行.

这篇关于在ng-repeat的每次迭代中执行脚本/功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆