2

Is it possibile in angular to load templates without web server, I found one example here: https://groups.google.com/forum/#!topic/angular/LXzaAWqWEus but for me it is only printing templates paths not content for them.

Is there any working example for this?

3
  • why would you want to do this? You can define the templates inline in most cases if you're simply trying to avoid having to setup a server environment I don't know why, it's trivial with lamp, wamp, mamp, or on linux with any package manager installing apache2 or some other web-server? Commented Jul 13, 2013 at 14:37
  • I need to make one app that will be shipped as is, without need of web server. Question is: is it possibile and how? Commented Jul 13, 2013 at 17:12
  • that's a valid reason I just get a bit annoyed with people who want to do it their way just because but don't really have a valid reason for doing things in a non-standard way. Don't have an answer but seems a legitimate request. Commented Jul 13, 2013 at 18:29

1 Answer 1

1

I'm ignoring the "no web server" part of the question. Here's an example on how you can put a template directly in a script tag and use it with a directive.

<body ng-app="myApp">
<script type="text/ng-template" id="templateTemplate.html">
     <div>
     I am the <span ng-transclude>{{templateAdjective}}</span> 
     template result.
     </div>
</script>

<div>
    <test>best</test>
    <test>optimal</test>
</div>

<script>
    var app = angular.module('myApp',[]);

    app.directive('test', function() {
        return {
            restrict: 'E',
            templateUrl: 'templateTemplate.html',    
            transclude: true,
            replace: true
        };
    });
</script>
</body>

template in script tag jsfiddle

Sign up to request clarification or add additional context in comments.

1 Comment

It's worth noting that a script tag with a type of text/ng-template and an ID inserts the contents of the script into the $templateCache service, so you can use the service to access that data outside of templateUrl properties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.