I am using ngDialog.open() to open a dialog. I want to pass in the template id to the function like this:
ngDialog.open({template: 'templateid'});
However, from the Network history, I find it is trying to fetch the templateid as a file on server.
I feel the ngDialog.open() function's interface design is a little confusing: The value of template options parameter can be either inline immediate HTML, or the file path of an HTML file on server, or the id of a <script> element. How should I distinguish them?
Thanks!
There are 2 options, not 3: either the filename for the template, or the template as a string. To provide the template as a string you set
plain: truein the options toopen(), so otherwise it will be interpreted as a filename.The third option -- selecting the template by id -- is actually using a filename that is in Angular's
$templateCache. If the name you provide is not in$templateCachefor some reason, then it will be requested from the server.One way to add a template to
$templateCacheis to use ascripttag like this (example from Angular docs):The main caveat here is that this must be somewhere inside the element that you have
ng-appon.The
$templateCachedocs also note that you can add a template in code by injecting$templateCacheand calling$templateCache.put()and get one by calling$templateCache.get()which could be useful in debugging your situation.