AngularJS变量不在函数之间更新

时间:2014-05-01 00:28:05

标签: angularjs

我是angularJS的新手,不知道我做错了什么。

我正在尝试实现一个编辑模式窗口,所以我正在制作要编辑的元素的副本,然后在完成图像上传后尝试访问它以更新图像src,但由于某种原因,范围变量为空在上传功能。 我做错了什么?

app.controller('projectsController', function($scope, $rootScope, $http, $modal) {

    $scope.edit = function(index){
        $scope.tempObj = angular.copy($scope.projects[index]);                      
        var modalInstance = $modal.open({
            templateUrl: 'projects/_edit_project',
            controller: ModalInstanceCtrl,
            resolve: {
                obj: function () { return $scope.tempObj; }
            }         
        }).result.then(function (project) { $scope.projects[index] =    project });
    }       

    $scope.processFileUpload = function(){
        console.log($scope.tempObj)    <--THIS RETURNS UNDEFINED                
    }



    var ModalInstanceCtrl = function ($scope, $modalInstance, obj) {        
        $scope.obj = obj;       
        $scope.ok = function () {
            $modalInstance.close($scope.obj);
        };
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };          
    };

}

0 个答案:

没有答案