Lit*_*ski 2 javascript controller angularjs
我正在使用AngularJS并且我已经进行了$ resource调用以获取单个值(例如,fetch使我得到14).
以下是我的控制器:
var MaxCount = $resource('/maxquestion/fetch', null,
{
getMaxQuestionCount: {method: 'GET', isArray: false}
});
$scope.maxQuestionCount = MaxCount.getMaxQuestionCount();
Run Code Online (Sandbox Code Playgroud)
现在我正试图$scope.maxQuestionCount在控制器中使用,做$scope.maxQuestionCount[0]了给我1并$scope.maxQuestionCount[1]给了我4
console.log($scope.maxQuestionCount)我,[object Object]
console.dir($scope.maxQuestionCount)我There are no child objects
我糊涂了.如何获取值14?
使用$resource像这样的数据结构真的没什么意义.事情是,$resource对于使用所有HTTP谓词的RESTful端点而言,它非常有用.为了方便起见,AngualarJS使用便捷方法扩展了传入的对象($ save,$ delete等).如果您返回原语,则没有扩展空间,其中一个主要好处$resource就消失了.
简而言之:如果您刚刚获取数据后,资源是一种过度的IMO,请坚持使用$http.该$http服务虽然被认为是较低级别,但是$resource非常方便且易于使用.举个例子,你可以写:
$http.get('/maxquestion/fetch').success(function(result){
console.log(result);
});
Run Code Online (Sandbox Code Playgroud)
有关更多示例,请参阅文档:http://docs.angularjs.org/api/ng.$ http
| 归档时间: |
|
| 查看次数: |
1401 次 |
| 最近记录: |