Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS $routeProvider injection fails in directive
    primarykey
    data
    text
    <p>I am currently trying to get in touch with AngularJS. Since I plan to build a rather complex web application I searched for an alternative to the ngView/$routeProvider combination to be found in the ng docs as I find them quite dissatisfying for a complex application with several navigation levels. So what I tried is to write a custom directive called <code>ngRoute</code> that could be used like this:</p> <pre><code>&lt;div ng-route="users"&gt; &lt;div ng-route=":id"&gt;&lt;/div&gt; &lt;div ng-route&gt;&lt;/div&gt;&lt;!-- default --&gt; &lt;/div&gt; </code></pre> <p>What I currently have is the following directive definition:</p> <pre><code>angular.module('app').directive('ngRoute', function($routeProvider) { var getRoute = function($el) { var parts = []; var $curEl = $el; while($curEl.length &gt; 0) { parts.unshift($curEl.attr('ng-route')); $curEl = $curEl.parent().closest('*[ng-route]'); } return parts.join('/'); } var directiveDef = { link: function(scope, $el, iAttrs, controller) { var route = getRoute($el); // Register route observer dependant on calculated route... } }; return directiveDef; }); </code></pre> <p>Unfortunately, I get an error due to the DI of the <code>$routeProvider</code> which I need for the registration of the route observation:</p> <pre><code>Error: Unknown provider: appProvider &lt;- app &lt;- ngRouteDirective </code></pre> <p>Did I miss something here? Also, feel free to critisize my approach (maybe someone already found a better solution for my problem).</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.
 

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