angular-tree-control icon indicating copy to clipboard operation
angular-tree-control copied to clipboard

templateUrl example doesn't work

Open dcardosods opened this issue 10 years ago • 5 comments

I copied the template from the demo, but didn't manage it to work. The template seems to only be loaded if already on cache, and when loaded I got the error Error: [$parse:syntax] Syntax Error: Token '{' is not a valid identifier at column 6 of the expression [node.{{options.nodeChildren}} | filter:filterExpression:filterComparator {{options.orderBy}}] starting at [{{options.nodeChildren}} | filter:filterExpression:filterComparator {{options.orderBy}}].

Is the example outdated? Any clue on how to make it work?

dcardosods avatar Oct 16 '15 17:10 dcardosods

can you share your full example?

Are you using instance template or global template?

The example http://wix.github.io/angular-tree-control/#externalTemplate works and is current.

yoavaa avatar Oct 18 '15 06:10 yoavaa

I'm using an instance template. I just noticed this directive depends on angular ~1.2.7. I'm using angular 1.4.4, so this might be the problem.

dcardosods avatar Oct 19 '15 16:10 dcardosods

I put the template in script tag and it worked.

<script type="text/ng-template" id="permissionTree.html">
...
</script>

And I saw the source code get the template directly from $templateCache

savokiss avatar Nov 09 '15 07:11 savokiss

Just verified it is working with angular 1.3.18. Can you share how you are using the feature?

On Mon, Nov 9, 2015 at 9:02 AM, Jason [email protected] wrote:

I'm using 1.3.18 and the templateUrl not working too

— Reply to this email directly or view it on GitHub https://github.com/wix/angular-tree-control/issues/167#issuecomment-154971840 .

yoavaa avatar Nov 09 '15 09:11 yoavaa

Seeing this behavior as well. The issue is that $templateCache.get(templateUrl) will only return the template if its already cached. Hence, if you embed the template in JavaScript it will be pre-cached and work as expected.

As a workaround, when you bootstrap your app on load, you can pre-cache the template manually if it isn't already cached (in case you compile the templates for a production build).

if (!$templateCache.get('app/custom-template.html')) {
  $templateCache.put('app/custom-template.html', 'app/custom-template.html');
}

phrough avatar Jan 10 '17 15:01 phrough