$ scope。$ parent在到达.success时返回null

时间:2014-11-19 08:10:38

标签: angularjs

所以我有一个childCtrl,它有一个添加客户的功能,在成功地将更新添加到它的父母的控制器之后。但是当我到达promise.success时,$ scope.parent为null。为什么会这样?

    $scope.addCustomer = function ( user ) {
        console.log( $scope.$parent ) //returns childscope object
        $scope.submitted = true;

        if ( $scope.addfrm.$valid ) {
            var newCustomer = JSON.stringify( user );
            customersFactory
            .addCustomer( newCustomer )
            .then( function ( data ) {
                console.log($scope.$parent) // returns null
                $scope.$parent.customers.push( data ); //returns error because $scope.$parent is null
                $scope.$parent.custLength = $scope.$parent.customers.length; //returns error because $scope.$parent is null
            } );
            $modalInstance.close();
        }
    };

我的github完整参考:github.com/xxryan1234/angularCustomerManagement

0 个答案:

没有答案