1

I am calling a preview method as follows

<span class="error-message">{{FilesNotSelected}}</span>

<input type="file" onchange="angular.element(this).scope().previewFile('firstLevel')">

In my script I am changing a scope variable as follows

 $scope.previewFile = function (uploadType) {
      $scope.FilesNotSelected = "Selected";
 }

I am unable to get the changed value to be displayed in the UI. Can someone please help me find the issues. It seems scope get changed.

Prashant
  • 3,823
  • 3
  • 25
  • 40

1 Answers1

0

The problem was with scope. Somehow the scope get changed and the updated value is not available. $scope.$apply(function (scope){}) helped solve this issue.

$scope.previewFile = function (uploadType) {
    $scope.$apply(function (scope) {
                      .
                      .
                      .
        reader.onloadend = function () {
            $scope.$apply(function (scope) {
                scope.FilesNotSelected = false;
                      .
                      .
                      .
                }
            }
        }
    }
}
Prashant
  • 3,823
  • 3
  • 25
  • 40