ruby-on-rails - Angular + rails : ngInclude directive not working

标签 ruby-on-rails angularjs templates partial-views angularjs-ng-include

我正在开发一个 Rails + AngularJS 应用程序。

这是我的文件结构:

app/
assets/
    javascript/
    templates/
       home.html
       partial.html

在 home.html.erb 文件中,我想包含partial.html.erb 文件。

home.html.erb

<ng-include src="'partial.html'"></ng-include>

我也尝试过

<ng-include src="'<%= asset_path('partial.html') %>'"></ng-include>

但还是不行...谢谢你的帮助

最佳答案

Setup gem "angular-rails-templates"

它会自动将您的模板编译为 JavaScript,并使它们可供 Angular 使用。之后你就可以像往常一样使用 ng-include 了。

<ng-include src="'templates/partial.tpl.html'"></ng-include>

关于ruby-on-rails - Angular + rails : ngInclude directive not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26330223/

相关文章:

ruby-on-rails - RSpec - 处理救援 block 内的重试

ruby-on-rails - 我可以阻止 Rails 将实例变量从 Controller 传递给 View 吗?

javascript - 如何从字符串值调用作用域上的函数

javascript - Angular Http put 方法在传递数据时出错(服务器期望表单 param )

c++ - 非虚拟成员函数可以使用模板参数吗?

ruby-on-rails - 生产模式下的 SSL 连接错误 Rails 3.2.3 瘦服务器

ruby-on-rails - 创建对象 FactoryGirl 时未定义方法。

angularjs - 使用异步数据编写 Angular 指令

templates - 难以理解 D 中的模板、模板混入、模板函数和作用域

c++ - 函数作为模板参数的推导指南