Skip to content

Instantly share code, notes, and snippets.

@karlwestin
Last active August 29, 2015 14:04
Show Gist options
  • Save karlwestin/7fd7e503b3ae1b25485f to your computer and use it in GitHub Desktop.
Save karlwestin/7fd7e503b3ae1b25485f to your computer and use it in GitHub Desktop.
What i mean about angular templates

Angular templates are very cool and all, there's jsut one thing im used to that im missing:

This is only about building/packaging your JS for prod

What i do today:

When i require a handlebars template with require.js:

require(["hbs!my-template"], function(tmpl) {
  //use the template in here  
});

HBS can parse the template, find dependencies and subdependencies, and include all those. Further, with require.js i can automatically get all the dependencies included in my build, just by asking for my-template

What grunt-angular-templates and all the other angular suggestions do:

They all seem to work more or less the same way:

  1. Scan directory for all files named "*.mysuffix", for example templates/dashboard/**/*.html
  2. Concat all those and add them to template cache, when your one single angular app starts

Why can't i do like everyone else?

  1. I have more than one angular app on a page
  2. I have several different pages, where some reuses widgets from each other The angular community seems to favor folder structures like this
  app
    /directives
      /dashboard
      /settings
    /controllers
      /dashboard
      /settings
    /templates
      /dashboard
      /settings

My opinion is that that stuff only works for small apps. For larger apps you need smth like this:

  app
    /widgets
      /account
      /other-thing
    /pages
      /dashboard
      /settings

A widget can be used on both dashboard/settings, and that folder contains a controller it needs, a template it needs and so. All code concerning one unit on the page is in one folder.

@karlwestin
Copy link
Author

including templates required by templates in my view should be the job of the template compiler.

Yeah, thats exactly my opinion too, except i haven't seen a template compiler that does it for angular :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment