Where can I place my ui.router templates in a rails application?

I am working on basic Rails / Angular and I am using ui.router to manage the views. However, when I try to use templateUrl, I get an error localhost/app/assets/templates/partial-home.html. Where should I put these partial parts to access the 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'
    });

});
+4
source share
1 answer

I use angular-rails-template , which also caches HTML templates in Angular $templateCacheto save AJAX calls or manually enter templates.

so for templates in: assets/javascripts/templates (I added instructions for your installation, did not test it though)

  • gem 'angular-rails-templates' and bundle
  • js (, application.js)

    //= require angularjs
    //= require angular-rails-templates
    //= require_tree ./templates
    

    ( : //= require_tree ../templates ( ), ignore_prefix)

  • : angular.module('myApplication', ['templates']);
  • 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' 
    
      }); 
    
    });
    

. , .

+3

Source: https://habr.com/ru/post/1543617/


All Articles