angularjs - Angular $compile template for dynamic email -


i trying load html template ng-repeats in , use $compile service compile , use compiled html in email.

the problem.... ok before asking let me set terminology... binding placeholder: {{customer.name}} binding value: 'john doe'

using $interpolate actual binding values not work ng-repeats.

example:var html = $interpolate('<p>{{customer.name}}</p>')($scope) returns: '<p>john doe</p>' ng-repeats not work

using $compile bindings placeholders ie {{customer.name}} need binding value 'john doe' .

example: var html = $compile('<p>{{customer.name}}</p>')($scope) returns: '<p>{{customer.name}}</p>'

once append page see binding values. email not page plus has ng-repeats $compile can compile

how can create dynamic email template after compiling it, returns html binding values , not binding placeholders can send email?

using $compile right way go. however, $compile(template)($scope) doesn't yield interpolated html expect right away. links compiled template scope interpolated during next $digest. desired html, need wait interpolation happen, so:

var factory = angular.element('<div></div>'); factory.html('<ul ng-repeat="...">...</ul>'); $compile(factory)($scope);  // interpolated html asynchronously after interpolation happens $timeout(function () {   html = factory.html();   // ... whatever need interpolated html }); 

(working codepen example: http://codepen.io/anon/pen/gxefr?editors=101)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -