问题标签 [angular-providers]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
angular - 没有简单组件的提供者
直到 5 分钟前它才起作用……这就是组件
这是主要的 app.module.ts
控制台错误是:
错误错误:未捕获(承诺):错误:StaticInjectorError [FormAddComponent]:StaticInjectorError [FormAddComponent]:NullInjectorError:没有FormAddComponent的提供者!错误:StaticInjectorError[FormAddComponent]:StaticInjectorError[FormAddComponent]:NullInjectorError:没有 FormAddComponent 的提供者!
typescript - 从另一个模块导入服务
在使用 AngularJS 1.x 框架开发 2 年后,我目前正在学习 Angular 框架(第 5 版),所以我问了自己很多问题,其中一个是正确导入由另一个模块提供的服务的方法我的申请。
假设我有一个CoreModule提供MyService服务的示例,假设该项目具有以下文件树:
现在假设我的clients页面需要从模块中注入MyService服务。CoreModule为此,我将放入模块MyService的提供者列表中CoreModule。我将CoreModule在我的AppModule.
如果我很好理解,通过进行这样的导入,我会告诉我的应用程序MyService在模块的 .ts 文件中需要它时使用该服务AppModule。
但我无法理解的是在我的应用程序代码中包含声明服务的 .ts 文件。事实上,如果我想使用该MyService服务,我会在Clients课堂上做类似的事情:
但是 TypeScript 需要引用声明服务的 .ts 文件。我的第一次尝试是按照文件树导入文件:
但这对我来说感觉不对,因为当我导入 Angular 服务时,我不必指定访问声明相关服务的文件的路径。服务示例HttpClient:
实际上,我希望能够通过引用模块而不是传递 .ts 文件的路径来在我的应用程序页面中导入我的核心服务。
那时,我什至不知道这是否可能,或者我是否误解了其他模块中服务的使用。
angular - 没有函数 (){} 的提供者!在角度 4
我正在为产品构建运行以下命令
运行此命令后,我没有收到任何错误,但是一旦我localhost:4200/在浏览器中运行,我会收到以下错误
任何帮助,将不胜感激
angular - multi:true 在 angular4 中的提供者中意味着什么
我HTTP_INTERCEPTORS在angular4中使用。为此,我创建HttpServiceInterceptor了实现HttpInterceptor接口并提供intercept方法定义的类。HTTP_INTERCEPTORS然后像这样注册提供者
这工作正常。但是我还是不明白multi:true这里是什么意思?我已阅读此答案。
如果我删除multi:true选项,则浏览器端出现错误
这是否意味着HTTP_INTERCEPTORS初始化多个指令或组件的多提供者?如果是这样,那么其他指令和组件是什么?
angular - errors.ts:42 ERROR 错误:未捕获(承诺):
我的聊天服务出现此错误我无法解决
这是错误
这是我的聊天服务的实际代码
angular - 在angular4中使用工厂提供程序时如何访问数据?
当我有这样的提供者时
我可以通过在组件中这样使用来获得价值
服务看起来像这样
现在,我如何在使用工厂提供程序时获得价值,即
现在我给出这个例子只是为了简化场景,但不仅仅是传递字符串,我想在工厂内调用一些服务
我的问题是,是否可以访问该变量,如果没有,那么我将如何获得我将在组件中使用的值
angular - 延迟加载模块中的 Angular 组件是否获取全局服务的副本?
Angular 文档我不确定我是否理解
Angular提供者文档指出:
当 Angular 路由器延迟加载一个模块时,它会创建一个新的注入器。此注入器是根应用程序注入器的子代。想象一棵注射器树;每个延迟加载的模块都有一个根注入器,然后是一个子注入器。路由器将根注入器中的所有提供程序添加到子注入器。当路由器在延迟加载上下文中创建组件时,Angular 更喜欢从这些提供程序创建的服务实例,而不是应用程序根注入器的服务实例。
在延迟加载模块的上下文中创建的任何组件(例如通过路由器导航)都会获取服务的本地实例,而不是根应用程序注入器中的实例。外部模块中的组件继续接收为应用程序根创建的实例。
问题
这是否意味着当我在延迟加载的模块中访问任何全局声明的提供程序时,我会访问它的副本,该副本与在根注入器中创建的实例是分开的?
假设我有两种情况:
情况A
- 根模块
AppModule- 提供
ProviderX - 宣布
AppComponent- 注入
ProviderX
- 注入
- 提供
- 懒加载模块
SubpageModule- 没有提供者
- 宣布
SubpageComponent- 注入
ProviderX
- 注入
情况乙
- 根模块
AppModule- 提供
ProviderX - 宣布
AppComponent- 注入
ProviderX
- 注入
- 提供
- 懒加载模块
SubpageModule- 提供
ProviderX - 宣布
SubpageComponent- 注入
ProviderX
- 注入
- 提供
在情况 A 中,in 的实例是与ProviderXinSubpageComponent相同的实例AppComponent还是不同的实例?我理解在情况 B 他们不是。
angular - injected service not executing correctly despite being provided at module level angular 4
I have a service called VenueAdminInceptionService
it is injected in the app module
The Service is used in the following way in my routing.
with the VenueadminactualComponent being the observeable with
venueprofileComponent,venueadmincateringComponent,VenuecreatededitComponent,VenueroomadminpageComponent,VenueadminsocialmediaComponent`
being the obeservers.
the code in the observable in the VenueadminactualComponent:
and then each observable is subscribed as such.
the console logs are blank. Which makes me think nothing is getting through.
I thought it could be my apps architecture, but thats why I provided the service app module wide.
the routing, in case that matters at all, although I can't see how, is as follows:
Assistance please! Punch and Pie await!
javascript - 在 AppModule 声明后添加提供者
Angular 2+ 以下列方式注册提供者:
我想与此声明站点分开注册应用程序范围的提供程序。
具体来说,我正在使用 NSwag 为我的整个 Web API 生成服务客户端,并且我希望将它们全部动态添加为提供程序。但是,我不确定如何做到这一点,因为@NgModule它是应用于此类的属性AppModule。
这可能吗?
