首页 \ 问答 \ 为什么Angular将'Provider'附加到我的服务名称?(Why does Angular append 'Provider' to my service name?)

为什么Angular将'Provider'附加到我的服务名称?(Why does Angular append 'Provider' to my service name?)

我想弄清楚为什么Angular在我没有声明的提供程序上给我以下错误。

错误:$ injector:unpr
未知提供者:dblServiceProvider < -

这是我工厂的骨架:

angular.module('fv.services', [])
.factory('dblService', function($q, $http) {
    this.getAll = function() {
        var deferred = $q.defer();

        var responsePromise = $http.post(URL, POSTPARAMS)
        .success( function(data, status, header, config) {
            // do something
        })

        return deferred.promise;
    };

    return {
        getAll: getAll()
    };
});

我尝试在控制器中实例化该服务,这是触发上述错误的地方。

.controller('searchCtrl', ['lotsOfInjections', 'dblService', function(lotsOfInjections, dblService) {
    // do something
}]);

为什么Angular附加“Provider”并寻找我尚未声明的提供者?


I'm trying to figure out why Angular is giving me the following error on a provider I have not declared anywhere.

Error: $injector:unpr
Unknown provider: dblServiceProvider <-

Here's the skeleton of my factory:

angular.module('fv.services', [])
.factory('dblService', function($q, $http) {
    this.getAll = function() {
        var deferred = $q.defer();

        var responsePromise = $http.post(URL, POSTPARAMS)
        .success( function(data, status, header, config) {
            // do something
        })

        return deferred.promise;
    };

    return {
        getAll: getAll()
    };
});

I try to instantiate that service in a controller, and this is where the error above is triggered.

.controller('searchCtrl', ['lotsOfInjections', 'dblService', function(lotsOfInjections, dblService) {
    // do something
}]);

Why does Angular append "Provider" and look for a provider I haven't declared?


原文:https://stackoverflow.com/questions/31970755
更新时间:2023-05-24 06:05

最满意答案

您可以添加&选择器字符串中的每个类:

pages = '&.home, &.about, &.contact'

.general
  {pages}
    a
      color black

甚至自动replace bif:

pages = '.home, .about, .contact'

.general
  {replace('\.', '&.', pages)}
    a
      color black

You can add & to every class in the string of selectors:

pages = '&.home, &.about, &.contact'

.general
  {pages}
    a
      color black

Even automatically with replace bif:

pages = '.home, .about, .contact'

.general
  {replace('\.', '&.', pages)}
    a
      color black

相关问答

更多
  • 您可以添加&选择器字符串中的每个类: pages = '&.home, &.about, &.contact' .general {pages} a color black 甚至自动replace bif: pages = '.home, .about, .contact' .general {replace('\.', '&.', pages)} a color black You can add & to every class in the st ...
  • 不幸的是,目前Stylus不支持字符串内插。 在这种情况下,您应该使用串联: $as-font-path = '../assets/fonts/'; @font-face { font-family: 'FontAwesome'; src: url($as-font-path + 'fontawesome-webfont.eot?v=4.3.0'); } Unfortunately currently Stylus doesn't support interpolation inside str ...
  • 您的示例不起作用,因为green , red和blue已经是颜色(具有rgba值的节点)。 要修复它,你可以使用字符串作为列表中的键: $green = #38ab0b $red = #ab130b colors = 'green' $green, 'red' $red for pair in colors .btn-{pair[0]} background: pair[1] 你也可以使用哈希(这个任务更好的方法): colors = { green: #38ab0b red: # ...
  • 我知道这是一个非常晚的答案,但是值得记录的内容永远不应该被忽略 - 正如您所知,问题是Stylus正在接收字符串,当它应该接收RGB或HSL颜色节点时。 Stylus中的字符串看起来像这样: 'text' ,当它们被编译成CSS时,它们按原样编译。 您需要呈现纯CSS文本,而不是字符串。 手写笔有一个内置函数,您可以使用该函数将该字符串转换为纯CSS文本: unquote() 所以你可以简单地改变一下 mainColor = randomColor() 至 mainColor = unquote(rando ...
  • 只需将值包装到括号中,如下所示: // *.styl $gutter = 1rem .sizeXS-m10 width 'calc(%s / %s * %s - %s)' % (100% 12 10 $gutter) Just wrap the values into brackets, like this: // *.styl $gutter = 1rem .sizeXS-m10 width 'calc(%s / %s * %s - %s)' % (100% 12 10 $gutter) ...
  • 在调用哈希值时应该使用冒号,否则Stylus无法区分选择器和哈希值。 所以, foo = { bar: { baz: { raz: 10px } } } qux = "raz" padding padding: foo["bar"].baz[qux] 应该工作正常。 You should use colon when calling hashes' values, as otherwise Stylus couldn't differentiate betw ...
  • 这有效吗? .test-animation-class &.ng-hide-remove &.ng-hide-add.ng-hide-add-active opacity 0 Is this works? .test-animation-class &.ng-hide-remove &.ng-hide-add.ng-hide-add-active opacity 0
  • 过滤器(如手写笔,降价等)在“编译时”执行,只执行一次。 但文本替换是在运行时完成的,因此过滤器无法访问变量。 过滤器只能访问原始文本,例如。 color #{color1}而不是color blue 作为一种解决方法,您可以创建一个辅助方法,您可以在其中进行手写笔模板化并在多个位置建议自己渲染(我只找到了使用降价过滤器的示例,但过滤器的工作方式相同,因此它们也适用于stylus过滤器): Jade:通过markdown过滤变量。 :markdown filter处理String变量的文本 :变量降价 Fi ...
  • 好。 所以,这个问题对于我提到的副本来说 是独一无二的 - 主要是因为循环中使用了2个数组。 您可能希望重命名该问题以供将来搜索。 首先 ,我花了很长时间才意识到我需要认真对待错误消息。 在你的情况下 - 它告诉你有括号 - 而且不应该 - 所以它们是出乎意料的。 删除它们。 Stylus语法大多就像SCSS一样 - 你所要做的就是输入更少的东西 - 并确保你的缩进是完美的。 在澄清规则的开始和结束时,缩进替换括号。 删除所有括号 - 和分号。 *(旁注 - 对变量使用$ var /以后可能需要它们 - 也 ...
  • 是的,像这样: IE = 'all and (-webkit-min-device-pixel-ratio:0) and (min-resolution: .001dpcm)' .div1 @media IE color red Yep, something like this: IE = 'all and (-webkit-min-device-pixel-ratio:0) and (min-resolution: .001dpcm)' .div1 @media IE col ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)