为什么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
最满意答案
您可以添加
&
选择器字符串中的每个类: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
相关问答
更多-
使用多个类创建Stylus变量并在编译中连接(Create Stylus variable with several classes and concatenate in compilation)[2024-01-19]
您可以添加&选择器字符串中的每个类: 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 ...
-
在Stylus中使用变量循环(Loops with variables in Stylus)[2023-06-01]
您的示例不起作用,因为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的Hashes(can't use Hashes from Stylus)[2022-10-18]
在调用哈希值时应该使用冒号,否则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 ... -
带有Stylus的嵌套CSS类(Nested CSS Classes with Stylus)[2023-04-03]
这有效吗? .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 -
在node.js中,如何将变量传递给:来自jade的stylus过滤器?(in node.js, how to pass variables to :stylus filter from jade?)[2022-08-26]
过滤器(如手写笔,降价等)在“编译时”执行,只执行一次。 但文本替换是在运行时完成的,因此过滤器无法访问变量。 过滤器只能访问原始文本,例如。 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 ...