Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs new Angular.js 1.1.5 resource returning promise then()函数错误,后跟另一个请求_Angularjs_Q_Angular Resource - Fatal编程技术网

Angularjs new Angular.js 1.1.5 resource returning promise then()函数错误,后跟另一个请求

Angularjs new Angular.js 1.1.5 resource returning promise then()函数错误,后跟另一个请求,angularjs,q,angular-resource,Angularjs,Q,Angular Resource,我正在使用最新的Angular.js,1.1.5,它通过资源调用返回promise。 当您有多个请求,然后又有一个请求依赖于这些请求时,正确的实现是什么 $scope.save = function() { var newids = []; angular.forEach ($scope.template.children, function (value){ //saves the children as a new template and returns t

我正在使用最新的Angular.js,1.1.5,它通过资源调用返回promise。 当您有多个请求,然后又有一个请求依赖于这些请求时,正确的实现是什么

$scope.save = function() {
    var newids = [];
    angular.forEach ($scope.template.children, function (value){
        //saves the children as a new template and returns the ID
        Template.$addNew(value).then(
            function( value ){newids.push(value);},
            function ( error ) {console.log ('error')}
        )
    });

    //updates the root template
    $scope.template.childrenIDs = newids;
    Template.$update($scope.template).then(
            function( value ){ console.log('successfully saved')},
            function ( error ) {console.log ('error')}
        )
}
为此,我得到一个错误:

TypeError:对象#没有方法“then”

模板为以下工厂,返回资源:

mongoAPI.
factory('Template', ['$resource', '$http', 'CONSTANTS', 'security', function($resource, $http, CONSTANTS, security) {
    var actions = {                        
        'addNew': {method:'POST'},   
    }
    var res = $resource(CONSTANTS.url, {}, actions)
    return res;
}]); 

完全公开的承诺目前仅在master(commit)中可用

从1.1.3开始,$resource通过
$then
(同样$resolved)公开了承诺的
功能:


完全公开的承诺目前仅在master(commit)中可用

从1.1.3开始,$resource通过
$then
(同样$resolved)公开了承诺的
功能:

供参考 从1.2.0开始,
$resource
公开了一个
$promise

Template.$addNew(value).$promise.then(
    function( value ){newids.push(value);},
    function ( error ) {console.log ('error')}
)

供参考 从1.2.0开始,
$resource
公开了一个
$promise

Template.$addNew(value).$promise.then(
    function( value ){newids.push(value);},
    function ( error ) {console.log ('error')}
)