AngularJS错误:未知提供商:sharedServiceProvider< - sharedService [英] AngularJS Error: Unknown provider: sharedServiceProvider <- sharedService

查看:188
本文介绍了AngularJS错误:未知提供商:sharedServiceProvider< - sharedService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照这个例子 http://jsfiddle.net/simpulton/XqDxG/ ,同时在这里找到 http://youtu.be/1OALSkJGsRw

I'm follow this example http://jsfiddle.net/simpulton/XqDxG/, also find here http://youtu.be/1OALSkJGsRw

var myModule = angular.module('myModule', []);
myModule.factory('mySharedService', function($rootScope) {
var sharedService = {};

sharedService.message = '';

sharedService.prepForBroadcast = function(msg) {
    this.message = msg;
    this.broadcastItem();
};

sharedService.broadcastItem = function() {
    $rootScope.$broadcast('handleBroadcast');
};

return sharedService;
});

后总是收到此消息。

After always getting this message

错误:未知提供商:sharedServiceProvider< - sharedService

Error: Unknown provider: sharedServiceProvider <- sharedService

我只是复制确切的jsfiddle的code。出乎我的意料。同样的错误。
疯狂的,在事业中的jsfiddle code的工作完美。

I just copy exactly the code of jsfiddle. My surprise. The same error. Crazy, cause at jsfiddle the code work perfectly.

可能是这个code德precated?

Could be this code deprecated?

推荐答案

由于的jsfiddle运行良好,当你移动code到应用程序中我presume问题只是开始,这个问题是在应用程序初始化逻辑。

Since the jsFiddle runs fine and problems only start when you move the code into your application I presume that the issue is in the application initialization logic.

您应该确保你的 NG-应用指令指定要使用的模块名称,例如: NG-应用=MyModule的。如果在的jsfiddle检查信息面板中,可以看到它的body标签配置,像这样:&LT;机身NG-应用=MyModule的&GT;

You should make sure that your ng-app directives specifies a module name you want to use, for example: ng-app="myModule". If you check the "Info" panel in the jsFiddle you can see that it has the body tag configured like so: <body ng-app="myModule">.

在任何情况下,你的问题是不与任何版本更改/框架功能去precated,我们就可以轻松地更新AngularJS到最新版本,它运行得很好。以下是更新的jsfiddle: http://jsfiddle.net/fRzAD/1/

In any case your issue is not linked to any version changes / framework features deprecated, we can easily update AngularJS to the latest version and it runs just fine. Here is the updated jsFiddle: http://jsfiddle.net/fRzAD/1/

这篇关于AngularJS错误:未知提供商:sharedServiceProvider&LT; - sharedService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆