Recommend to have another module to support angular2 template
tomalex0 opened this issue · 4 comments
This is really handy,
Would love to have an angular2 template engine for server side
I did some hacks to make it work for my scenario, but with limited support for angular2 .
https://github.com/tomalex0/compile-ng2-template/blob/master/index.js #
https://stackoverflow.com/questions/46351356/email-newsletter-implementation-using-angular2
This triggered me to look for similar implementation as yours
Interesting, isn't built-in angular server side rendering not an option for you? I haven't used it myself yet, but I know there is one.
If not, I think it would be fairly trivial to adapt directive selectors based on target version (untested):
'use strict';
function IfDirective($, data, options, angularTemplate) {
var targetAttr= options.version > 1 ? '*ngIf' : (options.prefix + "-if");
/**
* ht-if expression
*/
var htIfs = $("*[" + targetAttr + "]");
htIfs.each(function (i, elem) {
var expr = $(this).attr(targetAttr).trim();
$(this).before("<% if (" + expr + ") { %>");
$(this).after("<% } %>");
$(this).removeAttr(targetAttr);
});
}
module.exports = IfDirective
https://github.com/allenhwkim/angular-template/blob/master/directives/if.js
On the other hand repeat directive is a bit more complicated as new utility function would be required to extract variable names.
Aside of the above, what are your thoughts about ng-include? I am not aware of any replacement (it was anti-pattern anyway)
@FDIM , angular2 does have server side rendering. But not sure its going to solve what i'm trying.
In that case PR is welcome :)
Hi,
I also faced the same issue related to AngularJS training in Pune, I’m excited to uncover this page. I need to thank you for your time for this, particularly fantastic read!! I definitely really liked every part of it and I also have you saved to fav to look at new information in your site.