Skip to content

Instantly share code, notes, and snippets.

@Racum
Created August 14, 2013 21:09
Show Gist options
  • Save Racum/6235655 to your computer and use it in GitHub Desktop.
Save Racum/6235655 to your computer and use it in GitHub Desktop.

AngularJS - Templates

Loading all templates from a single file

index.html

<!DOCTYPE html>
<html ng-app="myApp">
<head>
...
</head>
<body>
    <div class="container" ng-view></div>
    <div id="template-loader"></div>
    <script src="angular.js"></script>
    <script src="app.js"></script>

templates.html

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

app.coffee

$.get 'templates.html', (data) -> $('#template-loader').html data
window.app = angular.module 'myApp', [], ($routeProvider) ->
    $routeProvider
        .when '/home',
            templateUrl: 'home.html'
            controller: 'HomeController'
        .when '/detail/:slug',
            templateUrl: 'detail.html'
            controller: 'DetailController'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment