Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute script/function on each iteration of ng-repeat

Tags:

angularjs

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>

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.

like image 367
Noitidart Avatar asked Dec 19 '25 04:12

Noitidart


1 Answers

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

This directive:

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

Used like:

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

Will execute.

like image 98
Jorg Avatar answered Dec 20 '25 22:12

Jorg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!