【发布时间】:2013-07-26 02:38:29
【问题描述】:
我正在尝试使用ngResource 进行AJAX 调用,在'a' 和'b' 下面的代码中都打印,但是来自Table.import() 的AJAX 调用没有进行。如果我将 AJAX 调用移到 onFileRead 之外,那么它可以工作。可能是什么问题?
var TableImportController = ['$scope','Table', 'project', 'table',
function($scope, Table, project, table) {
$scope.table = table;
$scope.project = project;
$scope.onFileRead = function(file) {
console.log('a');
Table.import({ data : file.data}, function() {
}, function() {
});
console.log('b');
};
}];
其中 Table 是 ngResource
.factory('Table', function($resource) {
var Table = $resource('/api/tables/:id:listAction/:itemAction',
{
id: '@id',
listAction: '@listAction',
itemAction: '@itemAction'
},
{
update: { method: 'PUT' },
import : { method: 'POST', params: { listAction: 'import' }},
}
);
return Table;
});
【问题讨论】:
-
能否把Table.import的代码包含进来?
-
@YeLiu 添加了 Table.import()
标签: angularjs ngresource