Execute script/function on each iteration of ng-repeat

后端 未结 4 2133
温柔的废话
温柔的废话 2021-01-15 14:25

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

{{aS
4条回答
  •  臣服心动
    2021-01-15 15:17

    As @Jorg said, create a directive:

    .directive('myCanvas', function(){
        return {
            scope: {
                size: '=size'
            },
            template: '',
            link: function(scope, elem, attrs){
                alert(scope.size);
            }
        };
    });
    

    Then inside your ng-repeat

    {{aSize}}

    This was quickly written and untested, but hopefully you get the idea. Just remember that the example above is just one way of binding, depending on your requirements for aSize (like can it be changed dynamically, etc).

提交回复
热议问题