gpt4 book ai didi

javascript - 获取错误 : Unkown provider: $urlMatcherFactory

转载 作者:行者123 更新时间:2023-11-29 21:54:30 25 4
gpt4 key购买 nike

Unkown provider: $urlMatcherFactory 

这是当我尝试在应用程序配置中注入(inject) $urlMatcherFactory 时 Angular 抛出的错误消息。

我已经包含了 ui-router JS 文件,并且最近几个月一直在使用它。

我需要做这样的事情:

var dateMatcher = $urlMatcherFactory.compile("/day/{start:date}");
$stateProvider.state('calendar.day', {
url: dateMatcher
});

作为this example显示。

通常像这样的代码不会识别$urlMatcherFactory。所以我尝试将其作为配置的依赖项注入(inject),但随后出现此错误。

最佳答案

在这个问答中Matching url with array list of words in AngularJS ui-router您可以看到如何使用 $urlMatcherFactory。还有一个链接到 working plunker .

在该示例中,$urlMatcherFactory 用于 .run():

  .run(['$urlMatcherFactory',
function($urlMatcherFactory) {

var sourceList= ['John', 'Paul', 'George', 'Ringo']
var names = sourceList.join('|');
var urlMatcher = $urlMatcherFactory.compile("/{source:(?:" + names + ")}/:id");

$stateProviderRef
.state('names', {
url: urlMatcher,
templateUrl: 'tpl.root.html',
controller: 'MyCtrl'
});
}
]);

这也意味着,如果你要在配置阶段使用它,你应该要求$urlMatcherFactoryProvider(见最后的Provider)

但是:在配置阶段使用提供者意味着我们可以配置它们。我的意思是配置提供者本身。稍后在运行阶段可评估(已配置)

Configuring Providers

You may be wondering why anyone would bother to set up a full-fledged provider with the provide method if factory, value, etc. are so much easier. The answer is that providers allow a lot of configuration. We've already mentioned that when you create a service via the provider (or any of the shortcuts Angular gives you), you create a new provider that defines how that service is constructed. What I didn't mention is that these providers can be injected into config sections of your application so you can interact with them!

First, Angular runs your application in two-phases--the config and run phases. The config phase, as we've seen, is where you can set up any providers as necessary. This is also where directives, controllers, filters, and the like get set up. The run phase, as you might guess, is where Angular actually compiles your DOM and starts up your app.

关于javascript - 获取错误 : Unkown provider: $urlMatcherFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com