Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ui bootstrap directive template missing

I'm currently testing out angular bootstrap-UI locally on my machine. When I try to recreate the example of accordion and dialog box. I get this error message in my console saying that template is missing.

Example of error: 404 Not Found - localhost/angular/template/message.html

When I look into ui-bootstrap-0.1.0.js the directive have a template URL.

What's the purpose of the templateURL for the directive?

Are those template suppose to be included when I download the whole angular bootstrap-UI zip file?

Am I missing other files that I should have include in my header?

<link rel="stylesheet" href="includes/css/bootstrap.css"> <script src="includes/js/angular.js"></script> <script src="includes/js/ui-bootstrap-0.1.0.js"></script> 
like image 957
iknowu2 Avatar asked Feb 19 '13 15:02

iknowu2


2 Answers

You have two choices:

  1. If you don't want to make your own templates and want the built in ones, you should download the ui-bootstrap-tpls-0.1.0.js file - this injects all the templates so they are pre-cached into your app: https://github.com/angular-ui/bootstrap/blob/gh-pages/ui-bootstrap-tpls-0.1.0.js#L1322

  2. If you do want to make some of your own templates, create a templates folder in your app, and download the templates from the angular-ui/bootstrap project. Then overwrite the ones you want to customize on your own.

Read more here: https://github.com/angular-ui/bootstrap/tree/gh-pages#build-files

edit:

You can also download bootstrap-tpls.js and still overwrite some of the directive's templateUrls with your own, using an AngularJS decorator to change the directive's templateUrl. Here's an example that change's datepicker's templateUrl:

http://docs.angularjs.org/api/AUTO.$provide#methods_decorator

myApp.config(function($provide) {   $provide.decorator('datepickerDirective', function($delegate) {     //we now get an array of all the datepickerDirectives,      //and use the first one     $delegate[0].templateUrl = 'my/template/url.html';     return $delegate;   }); }); 
like image 101
Andrew Joslin Avatar answered Sep 20 '22 20:09

Andrew Joslin


My 5 cents after wasting 2 hours with this problem. You should:

  1. Go to http://angular-ui.github.io/bootstrap/. Click on create a custom build and choose the features you use. (There is no point to pull 60k for 1 item).
  2. Include custom.tpls.js in my case it was ui-bootstrap-custom-0.10.0.min.js
  3. In your Angular module include 'ui.bootstrap.yourfeature' in my case it was 'ui.bootstrap.modal'
  4. and also include 'ui.bootstrap.tpls'. So my module complete depencies look like this:

    var profile = angular.module("profile",[ 'ui.bootstrap.modal', 'ui.bootstrap.tpls' ]);

  5. Save 2 hours and be happy :-).
like image 32
Svitlana Avatar answered Sep 17 '22 20:09

Svitlana