问题标签 [angular-services]
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.
javascript - Angular 的全局可用变量
我们正在将我们的 webapp 迁移到 Angular.js。传统上,我们创建了一个名为的全局对象app
,并用它来存储全局使用的函数、变量等。例如,活动用户的姓名和头像可能存储在app.user
.
随着向 Angular 的过渡app
,它不再只是一个对象,它是一个 Angular 应用程序模块。以 Angular 思维方式在全球范围内存储数据的正确方法是什么?它可能完全不同,那很好。我只是想确保我们做得正确。
我会做一些简单的事情app.global = {};
并app.global
在网站周围使用,但如果 angular API 更改为使用名为 的属性global
,那么修复将是一场噩梦。
angularjs - ng-click 执行属于不同控制器的 2 个方法
我有一个名称为PostController和CommentController
PostController的控制器具有功能showPost CommentController
具有功能showComment
我想在单击按钮时执行这两个功能
在不指定嵌套控制器概念的情况下如何做到这一点
ruby-on-rails - 使用 AngularJS 和 Rails 上传文件
我有一个模型BOOK
,将通过 angularjs 控制器插入书籍详细信息
这是我的看法:
我的 angularjs 控制器功能是:
问题是它存储了除书籍 pdf 上传之外的所有详细信息。它甚至没有通过名字。我该如何解决这个问题?任何建议,将不胜感激。
angularjs - 如何在我的应用程序中使用注入的 Angular 模块的服务?
我正在冒险将不同的角度模块注入我的应用程序。我创建的一个模块包含我想注入控制器的服务。有人对如何做到这一点有很好的解释吗?
我的 app.js:
myModule 包含我要注入的服务:
如何正确地将“coolService”注入此控制器的示例将很好地回答我的问题:
javascript - 如何在初始请求中提供 JSON 有效负载,以便在 JS 应用程序中使用
使用初始请求为我的 Angular 应用程序中的模型提供初始 JSON 数据的最佳方式是什么?(尽量减少对服务器的请求量)。
我应该直接将数据添加到服务器上的服务中,提供并包含一个单独的文件,还是有更“角度”的方法?
javascript - 角度服务/工厂未定义错误
我建立了这个工厂服务:
假设返回我在顶部声明的 usersObject 但控制台给了我一个未定义的对象错误。
这是控制器:
我对 Angular 很陌生。
javascript - Array Null out side loop ,但在 Angular.js 服务中包含值
如果这听起来像一个愚蠢的问题/尴尬的措辞,请原谅我,所以我的服务函数如下,我在函数之外有一个数组变量
然后功能如下,
提前致谢
更新
这是完整的代码..
我来自控制器的电话如下
angularjs - Angularjs UI won't update with service binding that's updated by promise?
I've spent the night on trying to figure this out and have finally decided to give up and ask for help.
I'm building a web-app with AngularJS that is designed to work with flakey connections (mobiles).
I'm trying to implement the functionality for a user to add a object (whether that's an appointment, book, etc is irrelevant) to the server.
Service that handles syncing objects with the server:
'app' service that the status bar is bound to:
Template binding to the 'app' service inSync property:
Specific object service that sends data from the controller to the syncUp service:
Everything is working as it should (data is being persisted to the server and the ID is being returned and replacing the tempId just fine. The problem is, when the inSync key on the 'app' service is updated, the class isn't added/removed from the div as it should be with ng-class in the template. If I load another route, that will force iterate through whatever internal cycle angular is doing and update the class on the template.
I've tried all manner of $apply() solutions, moving where the app.inSync key is set back to true, looping a function watching it. It's being set in all the right places (from debugging I know it's set back to true correctly), I just can't figure out how to make the change appear on the UI.
I tried: $rootScope.$apply(function() { app.inSync = true; });
Which gave me an error (already running a digest, or something).
So I tried the 'safeApply' version that has been circulated on many answers/blogs, which didn't throw the error, but didn't work either.
As far as I can figure out, the UI should be updated when promises are resolved (both the http and my syncUp.addObject promise are resolved, so I'm not sure why it's not working.
Any ideas? I need to keep the current implementation of promises to be able to set the returned ID from the server on the added object, to avoid a circular-dependency issue between the syncUp and object angular services.
Edit:
And the status bar directive:
javascript - Angularjs如何调用异步服务方法以及如何在监听器中使用依赖
我想在侦听器中使用依赖项,但 websocket 是undefined
并且想要在准备好时调用服务方法(依赖于异步方法)
谢谢你。
jsfiddle http://jsfiddle.net/8DHfY/3/或此处的代码