我正在学习 AngularJs。我发现自己很享受,但我坚持使用这段代码
我的控制器
$scope.getQuestionaires = function(){
var formdata = $scope.formdata;
var items = parseInt(formdata.items);
var num_letter = parseInt(formdata.num_letter);
var num_missing_letter = parseInt(formdata.num_missing_letter);
var send_data = {
api_type: 'select',
tb_name: 'tb_spelling',
tb_fields: false,
tb_where: false,
tb_others: "LIMIT "+items
};
return factory.getRecords(send_data);
}
我的工厂
factory.getRecords = function(data) {
return $http.post('models/model.php', {
params: data
}).then(function(response) {
records = response.data;
return records;
});
};
情况:当我console.log($scope.getQuestionaires)
,它返回
函数 (b,j){var g=e(),i=function(d){try{g.resolve((b||c)(d))}catch(e){a(e),g.拒绝(e)}},o=function(b){try{g.resolve((j|| d)(b))}catch(c){a(c),g.reject(c)}}; f?f.push([i,o]):h.then(i,o);return g.promise} controllers.js:307 function (a){function b(a,c){var d=e( );c?d.resolve(a):d.reject(a);return d.promise}function d(e,f){var j=null;try{j=(a||c)()}catch (g){return b(g,!1)}return j&&j.then?j.then(function(){return b(e,f)},function(a){return b(a,!1)}) :b(e,f)}return this.then(function(a){return d(a,!0)},function(a){return d(a,!1)})} controllers.js:307
[对象,对象,对象,对象]
问题:我的问题是我只想要对象数组,我该怎么做?我认为我的代码有很多需要改进的地方......我需要帮助:)
谢谢
===================================== 固定
感谢钱德曼尼的回答,
知道了!
我的控制器
$scope.createTest = function(){
$scope.getQuestionaires();
}
/*question getter*/
$scope.getQuestionaires = function(id,question){
/*send_data here*/
var records = factory.getRecords(send_data);
records.then(function(response){
$scope.questionaires = response.data;
});
}
我的工厂
factory.getRecords = function(data) {
return $http.post('models/model.php', {
params: data
});
};