Angularjs and image onload event?

2,215 views
Skip to first unread message

zied boufaden

unread,
May 12, 2014, 10:10:26 AM5/12/14
to ang...@googlegroups.com
i have a problem when accessing scope parameter inside an image onload event. i am using to upload an image and validate his size 

$scope.onFileSelect = function ($files) {
    $scope.loading = true;
    //$files: an array of files selected, each file has name, size, and type.
    file = $files[0];
    var img = new Image();
    img.src = _URL.createObjectURL(file);
    img.onload = function () {
        if (this.width > sizes.width && this.height > sizes.height) {
          console.log("good size");
        } else {
            console.log("check the sizes of your image");
            $scope.loading = false;
        }
    };
but the $scope.loading will remain the same after the the onload block instead of being equal to false. 

mark prades

unread,
May 13, 2014, 12:13:19 AM5/13/14
to ang...@googlegroups.com
You need to call $scope.$apply('loading') in the onload event listener.
Reply all
Reply to author
Forward
0 new messages