Note that there are some explanatory texts on larger screens.

plurals
  1. PODirectives messed up styling, AngularJS
    primarykey
    data
    text
    <p>My goal is to create a navigation-item directive, that will work with Twitter Bootstrap. My current code places the <code>&lt;li&gt;</code> tags further down a level, so I presume that's the reason bootstrap's CSS is not compatible.</p> <p>This is my directives.js file</p> <pre><code>angular.module('wdiary.directives', []) .directive('navitem', [function(){ return { restrict: 'E', transclude: true, templateUrl: 'partials/directives/navitem.html', scope: {} , link: function(scope, element, attrs) { scope.redirectRoute = attrs.redirect; var r = attrs.redirect; scope.itemName = r.substring(r.indexOf('/') + 1, r.length); } } }]); </code></pre> <p>The navitem.html directive template:</p> <pre><code>&lt;li ng-class = "{active: $route.current.activeNavigationItem == '{{itemName}}'}"&gt;&lt;a href="{{ redirectRoute }}" ng-transclude&gt; &lt;/a&gt;&lt;/li&gt; </code></pre> <p>A part of index.html:</p> <pre><code>&lt;div class="navbar" ng-controller = "NavigationController"&gt; &lt;div class="navbar-inner"&gt; &lt;a class="brand" href="#/"&gt;WDiary&lt;/a&gt; &lt;ul class="nav"&gt; &lt;navitem redirect = "#/write"&gt; Write &lt;/navitem&gt; &lt;navitem redirect = "#/list"&gt; List &lt;/navitem&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>And the controllers.js file</p> <pre><code>angular.module('wdiary.controllers', []) .controller('NavigationController', ['$scope', '$route', function($scope, $route) { $scope.$route = $route; }]) </code></pre> <p>I have inspected the result, this is what I can see:</p> <pre><code>&lt;ul class="nav"&gt; &lt;navitem redirect="#/write" class="ng-isolate-scope ng-scope"&gt; &lt;li ng-class="{active: $route.current.activeNavigationItem == 'write'}"&gt; &lt;a href="#/write" ng-transclude=""&gt; &lt;span class="ng-scope"&gt; Write &lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/navitem&gt; &lt;/ul&gt; </code></pre> <p>I think the solution would be to tell Angular not to wrap the list in another tag?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload