AngularJS HTML template/snippet management

淺唱寂寞╮ 提交于 2019-12-12 22:43:05

问题


I'm an Angular noob coming from Backbone+Marionette+Require.

If you have an app with a bunch of views and a bunch of directives each with their own HTML where are you putting all the HTML snippets? Most of the examples I see are storing them either inline, in their own script tags, or loaded asynchronously. One thing I love about RequireJS is that templates can live in their own files but can be compiled into the main JS file for production. I assume there's a grunt task or something similar? Maybe one that takes HTML from individual files and embeds them into individual script tags in a consolidated HTML file at build time?

Thanks.


回答1:


There is indeed a Grunt task to do this! Originally created by the Angular-UI Bootstrap team, the html2js task will take your templates and compile them into a JavaScript file (using angular's $templateCache) that can be concatenated with the rest of your scripts to form a single payload.

I haven't released it yet as I am still adding documentation, but take a look at ngBoilerplate, an AngularJS project kickstarter, to see it in context.

Update (28 Feb 2013): I just made a release of ngBoilerplate. You can check out the official site here: http://bit.ly/ngBoilerplate.



来源:https://stackoverflow.com/questions/15103574/angularjs-html-template-snippet-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!