angular-cron-gen icon indicating copy to clipboard operation
angular-cron-gen copied to clipboard

The move to template-url disallows the use of scoped values

Open icfantv opened this issue 8 years ago • 6 comments

One of the older versions of your library allowed for the specification of a user-defined template via an options.templateUrl property. The switch to a templateUrl function now no longer allows the user to use a scoped variable as, per the angular documentation, scoped values are not accessible because the template function is executed before the scope is even initialized.

This means that one cannot do template-url="{{ vm.template }}". I don't have a great solution here and it's clear that angular is not going to fix this issue.

You can see the issue here along with an attempted fix using injected $element, $attrs service values. You can ignore the parsing error and just look at the template value.

icfantv avatar Jan 24 '17 02:01 icfantv

There's an ugly way (read: hack) of using $templateCache to resolve this issue when using webpack's require and a template loader:

.run($templateCache => $templateCache.put('some-string', $templateCache.get(require('path/to/template.html')));

And then use some-string as the value of your template-url attribute.

It's ugly because you have the same entry in your cache twice.

icfantv avatar Jan 24 '17 18:01 icfantv

Nice. To be honest I haven't done much testing with loading another template. Do you have any suggestions?

vincentjames501 avatar Jan 24 '17 18:01 vincentjames501

I'm in the process of updating our template to account for all the changes from 0.0.6 (where there was a bug we just found about the hourly regex check was incorrectly matching a daily cron expression). I can link this issue in to my PR in our project when I have it done so you can see what we wound up doing.

icfantv avatar Jan 24 '17 20:01 icfantv

@vincentjames501 here's the PR for our project utilizing a custom template.

icfantv avatar Jan 25 '17 01:01 icfantv

@icfantv , would you be willing to update the README with a PR and document how you did it?

vincentjames501 avatar Feb 01 '17 18:02 vincentjames501

@vincentjames501 yea, but it's not straightforward. i had to look at your demo and the classes themselves to see what was exposed to put into a custom template. if you were to document your classes that might make it a lot easier.

icfantv avatar Feb 01 '17 18:02 icfantv