简体   繁体   中英

Error: $injector:modulerr Module Error seems there is an injection error in my directive but I don't understand whats wrong in my code

It seems there is an injection error in my directive but I don't understand whats wrong in my code and other posts in that issue didn't really help me figure that out. Anyone has an idea? Happy about any suggestions! Thanks!!!

my index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Flash Cards</title>
        <link rel="stylesheet" type="text/css" href="css/reset.css" />
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <script src="angular.min.js"></script>
        <script src="js/app.js"></script>
        <script src="js/navbar/navbar.js"></script>
        <script src="js/home/home.js"></script>
        <script src="js/about/about.js"></script>
    </head>
    <body ng-app="flashCards" >
        <navbar></navbar>
   hello
    </body>
</html>

my directive:

app.directive('navbar', function ($rootScope, $state) {
  return {
    restrict: 'E',
    scope: {},
    templateUrl: 'js/navbar/navbar.html',
    link: function (scope) {

        scope.items = [
            { label: 'Home', state: 'home' },
            { label: 'Unsere Praxis', state: 'about' },
            // { label: 'Leistungen', state: 'docs' },
            //  { label: 'Sprechstunden', state: 'sprechstunden' },
            //   { label: 'Kontakt', state: 'kontakt' },
            //    { label: 'Termin buchen', state: 'book' }

        ];

    }

  };
});

navbar html

<nav class="navbar navbar-static-top">
   <div class="container">
     <div class="navbar-header">
        <fullstack-logo></fullstack-logo>
    </div>
    <ul class="nav navbar-nav">
        <li ng-repeat="item in items">
            <a ui-sref-active="active" ui-sref="{{ item.state }}">{{ item.label }}</a>
        </li>

    </ul>
    <button ng-show="!user" ui-sref="login" class="btn login-button">Login</button>
    <div ng-show="user" class="welcome">
        <span>Welcome, {{ user.email }}!</span>
        <a >Logout</a>
    </div>
  </div>
</nav>

I guess it is hard to say for sure without trying it myself, but here is a possibility:

What is this $state you use in:

app.directive('navbar', function ($rootScope, $state) {

Is this the $state of ui router ? If so maybe you are missing a link to angular-ui-router.js , something like:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.0-beta.2/angular-ui-router.js"></script>

Also don't forget to make sure you added a dependency to your application module:

angular.module('app', ['ui.router']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM