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');
};
};
}
edit
andprocessFileUpload
is called?modalInstanceCtrl
outside the scope of theprojectsController
. Also, instead of$scope.obj = obj
try$scope.data = { obj: obj}