[英]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 我的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 导航栏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: 您在以下位置使用的$state
是什么:
app.directive('navbar', function ($rootScope, $state) {
Is this the $state
of ui router ? 这是ui路由器的$state
吗? If so maybe you are missing a link to angular-ui-router.js
, something like: 如果是这样,也许您缺少指向angular-ui-router.js
的链接,例如:
<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']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.