Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breadcrumbs in Angular

I want to use Angular's breadcrumb capability. I added this javascript file to my services folder.

I added a div to my header.html file to call the javascript. According to Angular, the div should look like this:

<div>
  <ul class="breadcrumb">
    <li ng-repeat="breadcrumb in breadcrumbs.getAll()">
      <span class="divider">/</span>
      <ng-switch on="$last">
        <span ng-switch-when="true">{{breadcrumb.name}}</span>
        <span ng-switch-default><a href="{{breadcrumb.path}}">{{breadcrumb.name}}</a></span>
       </ng-switch>
    </li>
   </ul>
</div>

The div is being created, and when I inspect it I see
<!-- ngRepeat: breadcrumb in breadcrumbs.getAll() -->

But no breadcrumbs. Any ideas?

like image 326
Edison Avatar asked Jun 08 '13 00:06

Edison


People also ask

What is a breadcrumb in frontend?

Breadcrumbs are a secondary navigation aid that helps users easily understand the relation between their location on a page (like a product page) and higher level pages (a category page, for instance).

What does breadcrumbs mean in HTML?

A breadcrumb navigation provide links back to each previous page the user navigated through, and shows the user's current location in a website.

How do you use Xng breadcrumbs?

✅ Zero configuration: Just add <xng-breadcrumb></xng-breadcrumb> anywhere in the app. Breadcrumb labels are auto-generated by analyzing Angular Route configuration in your App. ✅ Custom labels: Each route can have a custom label defined via Angular Route Config.

What are JavaScript breadcrumbs?

JavaScript is used to provide responsive functionality on smaller screens. The breadcrumb trail is designed to fit onto one line, no matter the length. If the breadcrumb trail becomes wider than the screen, the trail will get scrolled to the right so the current page is always in view.


1 Answers

It's not enough to just add the HTML to your header template file. Make sure you've also completed the following:

  1. Include breadcrumbs.js in your main HTML template (usually index.html):

    <script type="text/javascript" src="your-project-folder/services/breadcrumbs.js"></script>
    
  2. Include services.breadcrumbs as a module dependency for your main app:

    angular.module('myMainApp', ['services.breadcrumbs']);
    
  3. Finally, make sure you actually inject the breadcrumbs service into your controller, and then attach it to $scope:

    angular.module('myMainApp').controller('FooBarCtrl', function($scope, breadcrumbs) {
        $scope.breadcrumbs = breadcrumbs;
    
        // ... other controller logic ...
    });
    

You can see the implementation of Steps 2 and 3 in the angular-app project in the app.js file (refer to lines 6, 60, and 62).

like image 196
sergiopantoja Avatar answered Oct 04 '22 00:10

sergiopantoja