Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ui bootstrap custom templates in Rails

How can I use the custom templates of angular ui bootstrap in rails?

I mean, if I use pagination for example it will look for a templates/pagination/pagination.html template.

The problem is that rails won't serve templates in that path, it actually needs to be assets/templates/pagination/pagination.html using the <%= asset_path(....) %> helper.

Hacking the angular ui bootstrap javascript file is a way, but I don't feel like hacking it every time I get a new version.

like image 749
Jesus Rodriguez Avatar asked Jun 06 '13 11:06

Jesus Rodriguez


People also ask

What are the best AngularJS Bootstrap templates for website design?

While some of the AngularJS Bootstrap templates come exclusively for admins and dashboards, the others are for websites. Apzel is a perfect example of a powerful bundle of goodies for app and software websites. The set of six home designs and multiple practical internal pages covers all the necessary for you to start immediately.

How to add custom CSS files in a rails app?

Say that you want to add custom CSS files in your Rails app. Here are the steps that worked for me: Now you have to put the following line inside the <head> tag in the app/layouts/application.html.erb : And that's it. You don't even need to restart the server jut refresh the page.

Do I need jQuery or JavaScript for angular 2 support?

For Angular 2 support, check out ng-bootstrap , created by the UI Bootstrap team. This repository contains a set of native AngularJS directives based on Bootstrap's markup and CSS. As a result no dependency on jQuery or Bootstrap's JavaScript is required.

What are the best AngularJS dashboard templates?

Make the development process fun – with an AngularJS template! ArchitectUI is one of the more versatile dashboard templates available on the market. It includes nine main layouts along with multiple other page layouts and 100s of components. You can also pick from numerous preset color skins, finding the right one for your project much easier.


1 Answers

What I would suggest is to bundle custom templates with the library itself or inside a separate file. The technique to use is to fill in $templateCache with the content of your custom templates. Have a look at one of the files distributed with tamplates to see what I mean:

https://github.com/angular-ui/bootstrap/blob/gh-pages/ui-bootstrap-tpls-0.3.0.js#L2042

You can bundle templates into the $templateCache as part of the build process or prepare this file manually (in this case you need to write templates as JS strings).

Downloading individual templates via XHR for each and every directive would be wasteful as it would result in many XHR requests and would slow down your application. Also, if you preload templates into the $templateCache you can specify required path, one that doesn't need to be a valid path on your WWW server.

like image 109
pkozlowski.opensource Avatar answered Sep 24 '22 19:09

pkozlowski.opensource