0

I need to replace special keys in template which I download manually in angular before compiling and inserting into the DOM. Probably angular should have internally such functionallity, so I don't wanna use any 3rd party libraries.

Example:

  $http.get('app/components/shapes/box.html', {cache: $templateCache}).then(function (response) {

    var template = response.data;
    template = template
        .replace(/\{\{number\}\}/gm, number)
        .replace(/(\r\n|\n|\r)/gm, '');

  });
}

I can easily change key from {{$key}} to something else, but I assume angular should have internal functionality to do such manipulations.

For example:

var newTemplate = angular.funcWhichINeed(template, {
   varA: value1,
   varB: value2
});
vromanch
  • 939
  • 10
  • 22
  • Why not just modify the scope of the template? – TenorB Oct 30 '15 at 16:07
  • You can prevent tags from being interpolated, if this is what you need. Then you would not need to replace tags. – dfsq Oct 30 '15 at 16:09
  • the reason I'm doing it I need too pass compiled template to 3rd party library which has super strange process appending that to the DOM, and it provides for me an callback so I can execute compile on that target. – vromanch Oct 30 '15 at 16:13
  • basically that library doesn't insert an recived HTMLElement to the DOM, it modifies it to the string. – vromanch Oct 30 '15 at 16:16
  • I dont understand what you want - take template
    {{number}}
    - replace number -
    10
    - then pass result somewhere? But what the point of doing it?
    – Petr Averyanov Oct 30 '15 at 16:22
  • Take a look at the commend above. I need to pass compiled template to 3th party service, which take responsibility appending it to the DOM. But that service does the cast from object to string before inserting into the DOM. – vromanch Oct 30 '15 at 16:30

0 Answers0