问题标签 [ngresource]
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 ngResource $save 反馈
你好我正在使用 ngResource$save
方法,我得到了两种不同的行为,我不明白为什么
首先,我以这种方式使用它:
然后,当我执行类似操作时,我有另一个控制器,但即使从服务器收到 404 或 422 错误,第一个回调也会被执行并且错误回调被忽略。
有人对此有任何想法吗?我一直在谷歌搜索几个小时试图找到更多的文档,$save
但我仍然遇到这个问题。
谢谢你。
c# - Working example of AngularJS $resource searching items in Web Api
I'm learning how to use AngularJS's $resource to call a Web Api backend. I want to pass an object hierarchy in as criteria and get back an IEnumerable<Program>
. Here's an example of the criteria:
I have the same objects defined on the server in C#.
Here's how I am configuring $resource:
And I call it like this:
No matter what I try I either get null
as the criteria parameter or the action doesn't execute at all. I don't know if the problem is in angular, web api, or both. Here is the action:
Can someone help me get a working example going for searching and returning items using AngularJS $resource and Web Api?
angularjs - 使用 ngResource 通过 Angularjs 从我的 Slim PHP API 读取问题
我最近完成了一个与我的 Android 应用程序完美交互的 Slip PHP API 构建。我现在正在构建一个 Web 前端,对于我的生活,我无法理解如何使用 ngResource 的查询功能通过 GET 请求信息。
我的 index.html 文件是:
我的 app.js 文件:
我正在尝试阅读的信息(我已经从 Chrome 的高级 REST 客户端、浏览器和我的 Android 应用程序中成功完成了这项工作)位于http://api.discussorama.com/v1/topics(注意:我暂时禁用了 Slim PHP 中的身份验证中间件以使用 Angularjs 进行测试)。端点返回一个 json 响应,但除了“[]”之外,我在 Angular 中看不到任何东西。Angular 应用程序的链接是http://hwaelapps.com/discuss/web如果有人想看看到底发生了什么。在此先感谢您的帮助。注意:我已经尝试了几个 ngResource 配置选项,包括 urlencode 但它仍然没有接收到数据,所以我剥离了所有这些,所有代码都直接与问题中的一样。
angularjs - 从 angularJS $resource 中提取数据
我在使用 Angular 的 $resource 服务时遇到问题。由于我的 API 发送回一个完整的响应(标头等)以及数据对象中的一个错误字段,我需要从响应中获取一个特定的对象。使用 $http 服务执行此操作相当简单,但我不明白在哪里使用 $resource 服务获取这些参数。下面是有效的 $http 请求。
这是我在 $resource 的同一请求中失败的尝试:
编辑:更新上述代码后,这就是我在控制台中得到的。
但是,如果我将控制台日志更改为:
控制台简单地返回:
我哪里错了?如果它有助于相关页面的链接是http://hwaelapps.com/discuss/web
angularjs - 使用 ng-repeat 检索 AngularJS 中针对 restful Api 的帖子(模型关系)的评论
编辑:我决定使用 Restangular,因为 Lodash 库似乎与 AngularJS 配合得很好。我还有一个问题。Restangular 的 getList() 函数期望响应是一个数组,但是我的服务器响应包含两个参数,其中只有一个是数组。像这样的东西:
我假设我会在 RestangularProvider.setResourceInterceptor 中设置它,但我不太确定如何。有什么选择吗?我能够从我创建了一个数组的 .json 文件中读取响应,所以至少我知道我没有看错。:)
更新:我试过这个,但我得到:TypeError:无法设置未定义的属性“元数据”
<---------------------------------------------------- -------------------------------------------------- --------------------------------------------->
我对 angularJS 还是很陌生,但仍然不确定有关 CRUD 操作的几件事。我听到了很多对 ngResource 的赞誉,但也有人建议 $http 更适合更复杂的模型关系。我在这里有一个特定的问题,我想知道是否有人能指出我正确的方向。对于这个例子,我选择使用 ngResource,虽然我不太确定我有多喜欢它的数据处理。我的 Api 上有两个资源,主题和评论。Api 端点如下:
我编写了以下代码来获取主题:
然后在我看来像这样使用它(还没有问题):
我现在想做的是在主题的 ng-repeat 中查询评论 Api 端点,以显示该特定主题的评论。有没有办法从 ng-repeat 传递 t.id 来替换http://api.example.com/topics/:id/comments中的 :id以及我将如何处理这个问题。我最好还是使用 $http 或者 ngResource 是这个工作的好模块。提前致谢。
angularjs - AngularJS ngResource:如何始终使用相同的 catch 函数?
每次我使用任何 $resource 访问服务器时,我都想在失败时向我的用户显示相同的警报。
今天,它看起来像:
有没有办法为 ngResource 配置默认的错误处理功能?我正在寻找类似的东西:
javascript - 加载前的AngularJS ng-switch
我有一个 AngularJS 模板,如下所示:
我的控制器和工厂如下所示:
有没有办法防止“无可用数据”。在从资源中检索数据之前快速在屏幕上闪烁?
angularjs - How can I TransformRequest GET parameters with Angular resource?
When using ngResource/$resource, it is possible to implement custom (de)serialisation by specifying transformRequest/transformResponse. However these only control the request's body (data), so how can one manipulate the query parameters in a GET request?
Specifically, I would like to json-encode all the parameter values.
Simple case:
?user=123 is user with id 123
?user="123" is user with name 123
Complex case:
Passing objects/hashes in a GET request. For example using a mongo-like syntax to specify request criteria/projection. (Please note this question is not about mongo specifcally)
angularjs - $resource 获取无效的 URL
全部,
我的 angularjs 应用程序中的 $resource 调用遇到了一些问题。我花了几天时间寻找答案,从我可以看到我的代码应该可以工作,但它只是没有。如果有人能向我解释以下代码(在控制器中执行)的问题所在,我将不胜感激。
当我在开发控制台中检查 URL 时,它看起来如下:
我的理解是 id 参数应该替换为值(在我的例子中是 1),但显然这不会发生。那么,我做错了什么?
在此先感谢
丹尼尔·索德林
javascript - 未捕获的错误:[$injector:modulerr] AngularJS
首先,我想说我真的不想问这个问题,但是在两个小时不明白它的原因之后,它现在决定寻求帮助。
我想在我的应用程序中添加 ngResource 模块。在做之前,一切都很顺利。
所以我像这样创建我的应用程序:
然后我像这样配置它:
我得到这个错误,这意味着:
第 14 行当然是:
angular-resource.js 在 app.js 之前加载良好。
我不明白,我完全按照Angular Doc上所说的那样做:(
我希望我的问题不是完全愚蠢的,原因并不明显,因为我真的不知道我错在哪里!
如果你能帮助我,谢谢!
巴斯蒂安