0

I am new to angularJS and not sure what i'm doing wrong.

I am trying to implement an edit modal window so I am making a copy of the element to edit, then trying to access it once an image upload i done to update the image src, but for some reason the scope variable is empty in the upload function. What am i doing wrong ?

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');
        };          
    };

}
5
  • Are you sure $scope.projects[index] returns something when the edit function is called? Commented May 1, 2014 at 0:35
  • Yes, I'm actually using the resolved variable "obj" in the view and the data is there. Also checked the console.log to make sure and $scope.tempObj shows the correct object in the edit() function Commented May 1, 2014 at 0:41
  • Can you show us where edit and processFileUpload is called? Commented May 1, 2014 at 1:14
  • I added more code to show the main controller and the modal controller. Not sure if that's the best method to define it, I basically followed how they did in the docs: angular-ui.github.io/bootstrap/#/modal Commented May 1, 2014 at 1:39
  • Erm. Try creating the modalInstanceCtrl outside the scope of the projectsController. Also, instead of $scope.obj = obj try $scope.data = { obj: obj} Commented May 1, 2014 at 6:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.