Reputation: 735
I am working on a basic Rails/Angular app and am using ui.router to control the views. However when I try to use templateUrl
I get a localhost/app/assets/templates/partial-home.html
error. Where should I be putting these partials to make available to rails?
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
template: "this is a test of the state provider",
//templateUrl: 'app/assets/templates/partial-home.html',
controller: 'testCtrl'
});
});
Upvotes: 4
Views: 1228
Reputation: 3741
i'm using angular-rails-template, which also caches the HTML templates into Angular's $templateCache
to save AJAX calls or manually injecting the templates.
so, for templates in: assets/javascripts/templates
(i've added instructions for your setup, haven't tested it though)
gem 'angular-rails-templates'
and bundle
require the templates js in the manifest (probably application.js
)
//= require angularjs
//= require angular-rails-templates
//= require_tree ./templates
(in your setup, the include should be: //= require_tree ../templates
(not tested), and you should change the ignore_prefix settings)
angular.module('myApplication', ['templates']);
use your template in your ui-router js:
$stateProvider.state('home', {
url: '/',
// Template on: app/assets/javascripts/templates/partial-home.html
templateUrl: 'partial-home.html', //should work now :)
controller: 'testCtrl'
});
});
that's it. let me know how it goes
Upvotes: 3