问题标签 [angularjs-factory]
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.
angularjs - AngularJS:服务vs提供者vs工厂
AngularJS 中的Service,Provider 和有什么区别?Factory
angularjs - How can I extend the constructor of an AngularJS resource ($resource)?
I have a model, defined using $resource, that I am successfully loading.
Each loaded instance is, as promised, an instance of the class I defined.
(The example below is from the Angular docs. In it, User.get results in an object that is an instanceof User.)
However, imagine each User comes over the wire like this:
I defined a Preference factory that adds valuable methods to Preference objects. But when a User loads, those preferences aren’t Preferences, naturally.
I attempted this:
But it has no effect and never logs anything.
How can I make each item in my Users’ preferences array an instance of Preference?
javascript - AngularJS:什么是工厂?
我一直在做很多工作Angular.js,总的来说,我发现它是一个有趣且强大的框架。
我知道有很多关于服务、工厂、供应商和价值的讨论,但我仍然对 aFactory是什么感到很困惑。
工厂已在其他 StackOverflow 讨论中定义如下:
工厂
语法:module.factory( 'factoryName', function );结果:当将 factoryName 声明为可注入参数时,您将获得通过调用传递给 module.factory 的函数引用返回的值。
我觉得这个解释很难理解,也没有增加我对工厂是什么的理解。
有没有人有任何解释或现实生活中的例子来分享关于 a 到底Factory是什么以及为什么你应该使用它来代替 a Service、Provider或其他?
更新
Aservice 持有对任何对象的引用。
Afactory 是一个返回任何对象的函数
Aprovider 是返回任何函数的函数
-呸-
angularjs - 服务不包含在 angularjs 中
我已经将 requirejs 与 angularjs 应用程序集成在一起。现在我出错了'Provider commonService must define $get factory method. from myApp '
我如何在 requirejs 中包含服务?我在这里发布 serviceConfig 代码:
“服务/服务”和“插件/用户/服务”包含不同的服务。例如。
这里有什么问题?
angularjs - 使用缓存数据设置 angularjs 工厂的正确方法
我刚开始使用 Angular.js,我试图弄清楚如何设置一个工厂来显示缓存的数据,并在收到数据后将其替换为从 REST 服务检索的数据。
为了测试这一点,我只是对“缓存”数据进行硬编码。收到数据后,我希望使用从服务器接收到的最新数据更新 $scope.directory 变量。我可以得到它
这是我的工厂代码:
我的控制器有以下代码:
在我看来,我使用 ng-repeat 列出所有人员及其扩展名。
我希望在收到数据后更新视图。监视工厂数据更改的正确方法是什么?
javascript - 无法在 AngularJS 控制器之间共享数据?
我看过egghead.io关于在控制器之间共享数据的视频,但无法让它工作:
查看在 Plnkr 上运行的代码(带有额外的引导视图)
angularjs - ng-repeat 中的表达式如何工作?
我试图弄清楚如何使用 ng-repeat 循环遍历对象数组。
我有一个这样的工厂,里面有三组数据:
还有一个我注入工厂的指令:
在我看来,我试图像这样循环遍历它:
在这种情况下我需要使用什么表达方式?我无法从ng-repeat文档中理解这个表达式是如何工作的,我发现在“contentData 中的内容”中,contentData 指的是我的一组对象,但是第一个词是什么(内容,因为我在这里设置),它指的是什么?
另外,我是否正确设置了这个范围?就像上面的代码一样:
我从中得到的输出是三个空的内容框,所以我猜它正在循环通过它,但其中没有打印任何数据 - 即 {{contentData.boxTitle}} 只返回空
在这种情况下我是否正确使用了 ng-repeat ?
ajax - Angular js returning undefined object from factory
I have a controller and factory defined as below.
What confuses me is that I get the output undefined from my controller, and then the next line of console output is my list of objects from my factory. I have also tried changing my controller to
But I receive the error
Note: I found this information on using a factory through http://www.benlesh.com/2013/02/angularjs-creating-service-with-http.html
php - AngularJS - http POST请求在发送JSON时获得“SyntaxError:Unexpected token {”
已解决:问题出在我的 php 脚本中的第二个回显上。出于某种原因,它弄乱了我的东西。一旦我只留下第一个回声,一切似乎都很好。
我正在尝试使用 JSON 对象向 PHP 脚本创建一个简单的发布请求。出于某种原因,我收到“SyntaxError: Unexpected token {”但我检查了我的 JSON 并且它是有效的。我不确定这里发生了什么。我将不胜感激任何帮助。
这是我的PHP代码。事实证明,如果我评论 echo json_encode($_POST); 错误消失了。