I've seen a bunch of posts recommending using a directory per feature with angular. Today I've added RequireJS (AMD) to a new angular application I'm working on. I was using script
tags at the end of the body
tag, then I did some AMD restructuring and everything magically became 300% better.
It was all going great, the AMD style require
supported relative paths when working with JS files, but with templateUrl
, it starts at the root instead of in the directory I'm in. I've seen solutions like reading the "currently executing script file", I doubt that approach would work with AMD.
Is there a trick I don't know about to pass the path from somewhere? I don't mind doing some work per file, but I really don't want to do something like templateUrl: baseUrl + 'template.view1.html'
everywhere I use templateUrl
.
I'm using ui-router, if it matters (first day, yay).
What about using require.toUrl(...)
Take a look to the official docs: http://requirejs.org/docs/api.html#modulenotes-urls