为什么我无法将 $location 注入到我的 config() 中?

2024-05-18

为什么这会给我一个错误:

angular.module('app')
       .config(function($routeProvider, $locationProvider, $httpProvider, $location) {

未捕获的错误:未知的提供商:来自应用程序的 $location

但这条线没有?

angular.module("app")
       .factory("SomeResource", 
               function($q, $resource, $http, $location, AuthenticationService, Base64) {

这是同一个应用程序。能config只获取提供者和factory只获得非提供者?


只有提供者和常量可以注入到配置块中。

来自 AngularJS文档 http://docs.angularjs.org/guide/module在配置块上

  1. 配置块 - 在提供者注册和配置阶段执行。只有提供者和常量可以注入到配置块中。这是为了防止在完全配置服务之前意外实例化服务

  2. 运行块 - 在创建注入器后执行并用于启动应用程序。只有实例和常量可以注入到运行块中。这是为了防止在应用程序运行时进行进一步的系统配置。

本质上,配置块是在将提供程序注入控制器、服务、工厂等之前配置提供程序的地方。

angular.module('myModule', []).
 config(function(injectables) { // provider-injector
   // This is an example of config block.
   // You can have as many of these as you want.
   // You can only inject Providers (not instances)
   // into the config blocks.
 }).
 run(function(injectables) { // instance-injector
   // This is an example of a run block.
   // You can have as many of these as you want.
   // You can only inject instances (not Providers)
   // into the run blocks
 });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么我无法将 $location 注入到我的 config() 中? 的相关文章

  • 有没有办法用异步数据更新过滤器

    我已经构建了下一个角度过滤器 App filter cur2symbol CurrenciesService function CurrenciesService return function input iso input input
  • 关闭特定url上的AngularJS窗口

    我是 angularjs 的新手 所以这个问题对于经验者来说可能看起来很愚蠢 但我真的无法执行此操作 任何人都可以告诉我如何在到达特定网址后从 webview 返回到应用程序 就像我正在打开一个浏览器中的窗口用于支付过程 所以我需要的是 当
  • 项目组织和命名约定

    这在某种程度上是后续每个模块组件重复模块名称 https stackoverflow com questions 25005897 repeating module name for each module component问题 我们决定
  • 需要参考$log.log调用行号

    当我使用 Angular log 服务时 控制台中的所有行都会显示对 angular js 5687 的引用 而不是我调用 log log 函数的行 如何获得对我调用 log 的行的引用 另外 我有自己的围绕 log 的服务 如何引用对我的
  • 在父指令和子指令之间传递参数

    我有导航菜单的父指令和菜单链接的子指令 像这样的事情 menu menu
  • WebAPI 和 Angular JS Excel 文件下载 - 文件损坏

    我正在 WebAPI 中生成 Excel 文件 我将其 存储 在内存流中 然后放入响应 如下所示 var result new HttpResponseMessage HttpStatusCode OK Content new Stream
  • AngularJS 中的重定向状态

    这是状态配置 angular module grabhutApp config function stateProvider urlRouterProvider stateProvider ACCOUNT state account abs
  • 使用 ui-router 的 angular.js,如何仅重新加载一个视图?

    我有一个相当简单的待办事项应用程序 使用 angular js 我正在使用 ui router 库 我查看了 github 上的 ui router 示例 https github com angular ui ui router tree
  • AngularJS + jQuery 移动

    是否还有其他可能性来设计AngularJS以移动友好的方式应用程序CSS 我正在计划一个移动应用程序 并希望使用 AngularJS 进行逻辑和数据绑定 但我不想自己设计所有内容CSS The AngularJSFAQ说它使用jQuery
  • AngularJS templateUrl 与 template - 隔离范围

    我有以下指令 offerListSorters directive offersSorter myState templateCache function myState templateCache return scope control
  • Angularjs 循环遍历 $http.post

    当我循环遍历 Angularjs 的 http post 服务时 for var i 0 i lt scope tagStyles length i scope profilTag tag scope tagStyles i id tag
  • 使用 OpenIdConnect 和 angularjs 基于 Asp.net core 令牌的声明身份验证:禁止承载

    我正在使用 Asp net core rc2 和 OpenIdConnectServer 我正在使用 Angular 1 x 和 augular oauth2 几天后 我的错误已经转移到 Microsoft AspNetCore Hosti
  • AngularJS - 在等待数据/数据计算时加载图标

    我有一个简单的 Angular http get app factory countriesService function http return getCountryData function done http get resourc
  • 在 AngularJS 中动态显示图像

    我正在使用http请求从数据库获取图像的路径 并且图像位于服务器中 我想在 img src 中显示该图像 这是代码 http url user profile exec php method GET params uid user id s
  • 全局定义的 AngularJS 控制器和封装

    根据 AngularJS 的教程 控制器函数仅位于全局范围内 http docs angularjs org tutorial step 04 http docs angularjs org tutorial step 04 控制器函数本身
  • 如何为 ng-repeat orderBy 创建回调?

    寻找一种方法让 AngularJS 的 ng repeat orderBy 过滤器在完成渲染后执行回调 Markup div table thead tr th Name th th Age th tr thead tbody tr tr
  • $scope.$digest 之后立即触发事件

    在我的 AngularJS 应用程序中 有几个点我想等待 scope被处理到 DOM 中 然后在其上运行一些代码 就像 jQueryfadeIn 例如 有没有办法监听某种 digestComplete 消息 我当前的方法是 设置后立即 sc
  • 使用 jQuery 值更新 Angular 模型

    您好 我有一个附加在我的模型上的输入字段 当用户手动输入该字段时 会在更改时调用一个函数 这工作正常 并且模型按预期在控制台日志中反映
  • 如何使用 Angular Kendo UI 刷新网格数据源

    我使用 Angular Kendo UI 项目将 Telerik Kendo 网格与 Angular 结合起来 我有以下标记 div style height 600px div 以及我的控制器中的以下代码 scope thingsOpti
  • 使用 eclipse IDE 配置 angularjs

    我想开始使用 AngularJs 和 Java Spring 进行开发 我使用 Eclipse 作为 IDE 我想配置我的 Eclipse 以使这些框架无缝工作 我知道我可能要求太多 但相信我 我已经做了很多研究 你们是我最后的选择 任何帮

随机推荐