我正在尝试在html页面中显示配置的值author和version角值服务中的版本代码,但显示的不是作者的名字,这是html代码
author
version
<!doctype html> <html lang="en" ng-app="myApp"> <head> <meta charset="utf-8"> <title>My AngularJS App</title> <link rel="stylesheet" href="css/app.css"/> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div ng-view></div> <div>Angular seed app: v<span app-version></span></div> <div>Author is : <span app-author></span></div> <script src="lib/angular/angular.js"></script> <script src="js/app.js"></script> <script src="js/services.js"></script> <script src="js/controllers.js"></script> <script src="js/filters.js"></script> <script src="js/directives.js"></script> </body> </html>
这是指令…
angular.module('myApp.directives', []). directive('appVersion', ['version', function(version) { return function(scope, elm, attrs) { elm.text(version); }; }]) .directive('appAuthor', ['author', function(author) { return function(scope, elm, attrs){ elm.text(author); }; }]);
这是在其中配置author和version值的服务部分
angular.module('myApp.services', []). value('version', '0.1') .value('author','JIM');
我在开发人员控制台中遇到的错误是
Error: Unknown provider: authorProvider <- author <- appAuthorDirective
确保将这些模块( myApp.services 和 myApp.directives )作为主要应用程序模块的依赖项加载,如下所示:
angular.module('myApp', ['myApp.directives', 'myApp.services']);
塞子: http ://plnkr.co/edit/wxuFx6qOMfbuwPq1HqeM?p=preview