我如何参考使用Grails的资产插件静态HTML RSOURCE? [英] How do I reference a static HTML rsource using the Grails Asset plugin?
问题描述
我使用的Grails 2.4.1和 Grails的资产流水线插件的1.9.7版本。
I am using Grails 2.4.1 and the Grails Asset Pipeline Plugin version 1.9.7.
我有一个JavaScript文件(它定义了一个AngularJS指令),其需要引用静态HTML文件(其将被用作模板用于AngularJS指令)。
I have a javascript file (it defines an AngularJS directive) which needs to reference a static HTML file (which will be used as the template for the AngularJS Directive).
我如何引用HTML文件的资产目录中?
How do i reference the HTML file within the asset directory?
项目结构:
- 的Grails应用
- 资产
- 的JavaScript
- 指令
- hierarchyviewer.js
- hierarchyviewer.html
项目结构使用href=\"http://grails.org/plugin/angular-template-asset-pipeline\" rel=\"nofollow\">角模板资产管道的Grails插件的
Project Structure when using the Angular Template Asset pipeline grails plugin
- 的Grails应用
- 资产
- 的JavaScript
- 指令
- hierarchyviewer.js
- hierarchyviewer.tpl.html
directivea.js包括:
directivea.js contains:
angular.module('HierarchyViewer', []).directive('hierarchyviewer',function(){ return { restrict: 'EA', scope: {}, replace: true, controller: function ($scope, $http) { }, templateUrl: 'hierarchyviewer.tpl.html' } })
不过,当我尝试加载一个页面引用指示,我得到了指令/ directivea.html参考404。
However; when I try to load a page that references the directive, I get a 404 for the directives/directivea.html reference.
我如何正确地引用该模板使用资产管道插件的时候?
How do I reference the template properly when using the Asset Pipeline plugin?
推荐答案
角模板资产流水线插件笔者在这里。一对夫妇的调整,这应该为你工作。
Angular Template Asset Pipeline Plugin author here. A couple tweaks and this should work for you.
- 插件期望模块名称是在骆驼。
- 的插件也将删除文件名.tpl所以你会在这种情况下,与文件最终命名为hierarchyviewertemplate.js
- 确保文件名(包括扩展名)是唯一的。
在最后一点上,由于资产管道插件会忽略资产目录中的父文件夹,在每个以下位置的文件将引起冲突:
On that last point, since The Asset Pipeline plugin will ignore the parent folders within the assets directory, a file in each of the following locations would cause a conflict:
-
/assets/javascripts/hierarchyviewertemplate.js
-
/assets/templates/hierarchyviewertemplate.tpl.html
/assets/javascripts/hierarchyviewertemplate.js
/assets/templates/hierarchyviewertemplate.tpl.html
在实际的code而言,这样的事情应该工作更好地为您:
In terms of the actual code, something like this should work better for you:
//= require_self //= require_tree /hierarchyViewer angular.module('hierarchyViewer', []).directive('hierarchyviewer',function(){ return { restrict: 'EA', scope: {}, replace: true, controller: function ($scope, $http) { }, templateUrl: 'hierarchyviewertemplate.html' } });
这会认为你hierarchyviewertemplate.tpl.html文件位于
This would assume that your hierarchyviewertemplate.tpl.html file is located at
在grails-app - >资产 - >模板 - > heirarchyViewer - > hierarchyviewertemplate.tpl.html
grails-app -> assets -> templates -> heirarchyViewer -> hierarchyviewertemplate.tpl.html
如果您的模板包含在插件中,替换
require_tree
与require_full_tree
If your template is contained within a plugin, replace
require_tree
withrequire_full_tree
希望有所帮助。
这篇关于我如何参考使用Grails的资产插件静态HTML RSOURCE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 指令
- 的JavaScript
- 资产
- 指令
- 的JavaScript