0

I have a custom directive and rendering that directive using ng-repeat. what I need is I want to compile interpolation before passing into my custom directive.

Find plnkr below

https://plnkr.co/edit/bjdBSKCFPhgbE2aREupy?p=preview

Here I want to compile interpolation in this code <display-id mycompile id={{op.id}}> </display-id> using mycompile directive.

    app.directive('mycompile', function ($compile, $interpolate) {
        return {

            restrict: 'EA',
            replace: true,
            compile: function ($scope, $elm, $attrs) {
                return {
                    pre: function ($scope, $elm, $attrs) {

                            $interpolate($elm[0])($scope);

                    }
                }
            }

        }
    })
G07cha
  • 4,009
  • 2
  • 22
  • 39
Kbvin
  • 216
  • 3
  • 13
  • Why aren't you simply using a scope binding? Why are you trying to interpolate the element, instead of the value of the id attribute? What are you really trying to achieve? – JB Nizet Nov 07 '17 at 07:21

1 Answers1

0

$interpolateProvider expects string to be an argument, so what you need is to convert your element to string and then back to DOM element if you want, it could be achieved with outerHTML property like so:

$interpolate($elm.prop('outerHTML'))($scope);
G07cha
  • 4,009
  • 2
  • 22
  • 39