Giter Club home page Giter Club logo

Comments (23)

adriantadros avatar adriantadros commented on September 25, 2024 5

Actually what solved it for me was making sure image and result-image were not set directly on the $scope object.

So instead of:

$scope.image = '';
$scope.croppedImage = '';

I used:

$scope.image = {
   originalImage: '',
   croppedImage: ''
};

Then updated my directive to:

<img-crop
   image="image.originalImage"
   result-image="image.croppedImage"></img-crop>

And that seemed to resolve the problem. I think it is something to do with the way angular treats string values assigned to $scope by value rather than by reference.

from ngimgcrop.

alexk111 avatar alexk111 commented on September 25, 2024

@TrkiSF2 Can you provide a demo of the issue on JSFiddle?

from ngimgcrop.

onur-celik avatar onur-celik commented on September 25, 2024

in my case it's not working on safari and firefox but working on chrome
im using a mac and agular version is 1.2.26(latest) please help

from ngimgcrop.

alexk111 avatar alexk111 commented on September 25, 2024

Guys, please provide demo pages so that the problem could be reproduced. Otherwise it's impossible to find what causes it and solve the problem. Thank you.

from ngimgcrop.

asheshambasta avatar asheshambasta commented on September 25, 2024

Same issue here. Works in the same case with JSFiddle but not in my controller. 'image' works, when I bind it to a scope variable and then add the scope variable as an ng-src of an tag, but result-image is always blank.

Looked promising, but I'm afraid this is a deal breaker.

from ngimgcrop.

GabiAxel avatar GabiAxel commented on September 25, 2024

UI's modal scope messes with the img-crop directive's scope. In updateResultImage() there is a check for if(angular.isDefined(scope.resultImage)) and it is false. I overcame this by opening the modal with a scope that contains "resultImage" (value doesn't matter, as long as it's defined) like this:

$modal.open({
   scope: angular.extend($rootScope.$new(), {
      resultImage: ''
   })
});

or even simpler, if you use a controller for the modal, set $scope.resultImage = '' in it.

from ngimgcrop.

asheshambasta avatar asheshambasta commented on September 25, 2024

All that is a workaround yes. But to have it not work with something as standard as UI is an alarm bell. 

We already switched to jQuery's cropper and wrote a custom directive around it which works really well. In any production situation, these workarounds can give me sleepless nights. 


Best,

Ashesh Ambasta

On Sun, Jan 4, 2015 at 4:52 PM, Gabriel Axel [email protected]
wrote:

UI's modal scope messes with the img-crop directive's scope. In updateResultImage() there is a check for if(angular.isDefined(scope.resultImage)) and it is false. I overcame this by opening the modal with a scope that contains "resultImage" (value doesn't matter, as long as it's defined) like this:

$modal.open({
   scope: angular.extend($rootScope.$new(), {
      resultImage: ''
   })
});

Reply to this email directly or view it on GitHub:
#18 (comment)

from ngimgcrop.

olpapchenko avatar olpapchenko commented on September 25, 2024

I have the same problem even with:

$modal.open({
   scope: angular.extend($rootScope.$new(), {
      resultImage: ''
   })
});

I just can not understand why bidirectional bind variable: result-image is not updated inside my controller. Inside updateResultImage() is updated. But the value of my corresponding variable in controller is not. I tryed to use callback onChange. The call back is called but instead of result image i get undefinde. Futher more i tryed to define my own call back on the directive imgCrop and pass the value of the result image inside it. How ever the result is the same - the call back called but i get undefined as argument. Even more i tryed just to pass strign literal to the callback - still get undefined. Sorry i can not reproduce this problem. This problem is reproduced only in my development env.

from ngimgcrop.

adriantadros avatar adriantadros commented on September 25, 2024

I have the exact same problem described by rocketmannot. Has anyone managed to resolve this?

from ngimgcrop.

adriantadros avatar adriantadros commented on September 25, 2024

Update: I managed to resolve this by setting change-on-fly="true".

See below:

<img-crop
   image="imageData"
   result-image="croppedImage"
   area-type="square"
   result-image-format="image/png"
   result-image-size="60"
   result-image-quality="0.6"
   change-on-fly="true"></img-crop>

from ngimgcrop.

coommark avatar coommark commented on September 25, 2024

Yo @asheshambasta! Can you share the directive or a little sample of the one you did with Cropper? Pls

from ngimgcrop.

santhoshses avatar santhoshses commented on September 25, 2024

@alexk111 i want to disable the resize property of the croping tool. actually i need a fixed width and height for the croper.Please help me out on this.

from ngimgcrop.

leob avatar leob commented on September 25, 2024

@adriantadros Excellent!!!

I had the same issue, the solution is simple and works flawlessly, this should be mentioned in the documentation (README).

from ngimgcrop.

ortho23 avatar ortho23 commented on September 25, 2024

@adriantadros comment worked for me, thanks!

from ngimgcrop.

txtbits avatar txtbits commented on September 25, 2024

@adriantadros Solved. Simple solution. Thank you!

from ngimgcrop.

lechengyu avatar lechengyu commented on September 25, 2024

@adriantadros It really helps! Thank you!

from ngimgcrop.

ldwonday avatar ldwonday commented on September 25, 2024

@lechengyu Can you paste the full code?

from ngimgcrop.

anaganisk avatar anaganisk commented on September 25, 2024

here is what I did in case anyone needs a cleaner solution without any workarounds

angular.module('poch').directive('addprofile',function(){
return{
        restrict: 'E',
        templateUrl: 'client/modules/add-profile-details/add-profile.html',
        controllerAs: 'addProfileController',
        controller: function($scope,$reactive){
            var vm = this;
            $reactive(this).attach($scope);
            this.helpers({
                imgSrc: function(){
                  return undefined;
                },
                image: function(){
                    return {
                        originalImage: undefined,
                        croppedImage: undefined
                    };
                }
            });
            this.addAvatar = function(files){
                if (files.length > 0) {
                    var reader = new FileReader();
                    reader.onload = function(e){
                        $scope.$apply(function(){
                            vm.image.originalImage = e.target.result;
                        });
                    };
                    reader.readAsDataURL(files[0]);
                }
                else {
                    this.image.originalImage = undefined;
                }
            };
            this.saveAvatar = function(){
                this.imgSrc = this.image.croppedImage;
                this.image.originalImage = undefined;
            }
        }
    }
});

from ngimgcrop.

bitf09a013 avatar bitf09a013 commented on September 25, 2024

@adriantadros Thank you mate!

from ngimgcrop.

felipedssantos avatar felipedssantos commented on September 25, 2024

@adriantadros Thank you man, it work for me!

from ngimgcrop.

kabrice avatar kabrice commented on September 25, 2024

Nothing is working for me :(

from ngimgcrop.

ignj avatar ignj commented on September 25, 2024

@kabrice try this (forget the part of ngFileUpload)

from ngimgcrop.

lahong avatar lahong commented on September 25, 2024

@ignj thanks for posting the fiddle awesome stuff,can you please post and example sending the image with form field aswell

from ngimgcrop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.