Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use AngularJS routes with Haml templates in a Rails app
    primarykey
    data
    text
    <p>I have app/assets/templates/api-list.haml that I want to use as an AngularJS template. I followed <a href="http://minhajuddin.com/2013/04/28/angularjs-templates-and-rails-with-eager-loading" rel="nofollow">this tutorial</a> to create a templates.js file that inserts all my compiled Haml AngularJS templates into <code>$templateCache</code>. However, I can't seem to make these cached templates work with my AngularJS routes:</p> <pre><code>api_app.config(['$routeProvider', ($routeProvider) -&gt; $routeProvider.when '/', templateUrl: 'api-list' controller: api_app.ApiListController $routeProvider.otherwise redirectTo: '/' ]) </code></pre> <p>When I load my app, I see a 404 error in the browser console because it tried to do a request to <code>http://localhost:3000/api-list</code>. I can look at /assets/templates.js in the browser and see that <code>$templateCache.put("api-list"</code> is defined, so there should be a template called "api-list". I am loading templates.js in my page before defining routes.</p> <p>I also tried injecting <code>$templateCache</code> in my route config like so:</p> <pre><code>api_app.config(['$routeProvider', ($routeProvider, $templateCache) -&gt; $routeProvider.when '/', template: $templateCache.get('api-list') controller: api_app.ApiListController $routeProvider.otherwise redirectTo: '/' ]) </code></pre> <p>This causes an <code>Uncaught TypeError: Cannot call method 'get' of undefined from ApiApp</code> error though. If I change the first line to <code>api_app.config(['$routeProvider', '$templateCache', ($routeProvider, $templateCache) -&gt;</code>, I instead get the error <code>Uncaught Error: Unknown provider: $templateCache from ApiApp</code>.</p> <p>How can I convince my routes to use the template from <code>$templateCache</code> instead of trying to load it via a new request?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload