Widget ng-include not pulling in template

krr
Mega Guru

We're trying to use a template within a widget for the service portal and even the simplest example is not working, so there must be a step I'm missing.

From examples in the system with OOTB widgets they use this to pull in the template

<div ng-include="template_id"></div>

When doing the same thing for a simple example below, the template doesn't load. What's the proper method to pull in a ng-template?

HTML Template

<div>
  <h1>This is a widget</h1>
  <div ng-include="test"></div>
</div>

Client Script

function() {
  /* widget controller */
  var c = this;
}

Server Script

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */

})();

Angular ng-template: test

<strong>Hello world!</strong>

HTML Output

<div> 
 <h1>This is a widget</h1> 
 <!-- ngInclude: test --> 
</div>

Output screenshot

find_real_file.png

1 ACCEPTED SOLUTION

It should also work like:

<div ng-include="'test'"></div>

View solution in original post

8 REPLIES 8

DScroggins
Kilo Sage
Hello. Have you verified that the template is included with your widget? When viewing the widget in the platform the related list 'templates' should have your 'test' template which you are attempting to use. If not add it then try again. Hope this helps. --David

It's associated to the widget. I've reproduced this in a dev instance so I have to be doing something odd.

find_real_file.png

Ok then try to call the template like so:

<div ng-include="test.html"></div>
 

I've tried naming it test and importing with test.html and test. I've also named it test.html and imported with test and test.html.

So far no luck.

I've attached the update set if it's of interest

https://instance.service-now.com/sp?id=test