2014-06-06 40 views
4

我正在使用基本的Rails/Angular應用程序,並使用ui.router來控制視圖。但是,當我嘗試使用templateUrl時,出現localhost/app/assets/templates/partial-home.html錯誤。我應該把這些部分放到軌道上?我在哪裏把我的ui.router模板放在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' 
    }); 

}); 

回答

3

我使用angular-rails-template,這也緩存HTML模板成角的$templateCache保存AJAX調用或手動注入模板。

所以,在模板:assets/javascripts/templates (我加你的設置說明,還沒有測試但它)

  • gem 'angular-rails-templates'bundle
  • 要求清單中的模板JS(大概application.js

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

    (在你的設置中,包括應爲://= require_tree ../templates(N OT測試),你應該改變ignore_prefix settings

  • 注入的依賴關係:angular.module('myApplication', ['templates']);
  • 使用模板在UI路由器JS:

    $stateProvider.state('home', { 
    
        url: '/', 
    
        // Template on: app/assets/javascripts/templates/partial-home.html 
    
        templateUrl: 'partial-home.html', //should work now :) 
    
        controller: 'testCtrl' 
    
        }); 
    
    }); 
    

就是這樣。 讓我知道它是怎麼回事

+0

你也必須有鏈輪版本> = 2.12 –

相關問題