Passing object reference to Angular JS directive

I am trying to pass an object reference (or a copy) as an attribute to my custom directive inside a loop. I cannot seem to make this work without the variable being on the controller scope.

`function decode() {

        var html="";

        for(var element of $scope.currentPage.elements) {
            html += `<pv-${element.type} id="${}" element="element"></pv-${element.type}>`;
        var j = $(html);  // Compile will not work unless the same var is used in statements below!

I need the element counter variable sent to the directive. How can I do this without creating a bunch of different variables on my controllers scope?


Project for Student Management System and use of CURD Operation

Details,PoC and patches for CVE-2021-45383 & CVE-2021-45384