本文介绍了AngularJS模块中的html模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在AngularJS模块中包含html模板,而不必将它们作为字符串放入js代码的templateCache中?

Is there a way to include html templates in AngularJS modules without putting them as strings into js code into the templateCache?

推荐答案

我们完成此操作的方法是将html模板编写为独立的html文件,然后使用执行任务,将其压缩为字符串(处理所有转义的字符等)并将其注入模板缓存中.两全其美,因为开发人员可以在源代码控制下处理单个HTML文件,但是我们极大地减少了到服务器的往返次数,以便在运行时将模板下拉到应用程序.(以预先加载为代价)

The way we've accomplished this is to write our html templates as standalone html files, then use a grunt task to crunch them into strings (handles all the escaping etc) and inject them into the template cache. best of both worlds, as the developers can work on individual HTML files all under source control, but we drastically reduce roundtrips to the server to pull the templates down to the app at runtime. (At the cost of up-front loading)

这篇关于AngularJS模块中的html模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:59