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
});
6
  • Why not just modify the scope of the template? Commented Oct 30, 2015 at 16:07
  • You can prevent tags from being interpolated, if this is what you need. Then you would not need to replace tags. Commented Oct 30, 2015 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. Commented Oct 30, 2015 at 16:13
  • basically that library doesn't insert an recived HTMLElement to the DOM, it modifies it to the string. Commented Oct 30, 2015 at 16:16
  • I dont understand what you want - take template <div>{{number}}</div> - replace number - <div>10</div> - then pass result somewhere? But what the point of doing it? Commented Oct 30, 2015 at 16:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.