1

I am learning AngularJS, Currently I am doing one exercise, which is having angularjs ng-click function, I am getting the result on second click of my upload button using ng-click(As I am displaying my json content after clicking on 'upload' button), I don't know where I am doing wrong ? Please let me know.

4
  • I have created fiddle at: jsfiddle.net/mavdhana/u3zgrgcx/1 Commented Oct 9, 2015 at 12:13
  • 1
    can you show us what code you have? Commented Oct 9, 2015 at 12:13
  • I forgot to include fiddle in my question, I have created at: jsfiddle.net/mavdhana/u3zgrgcx/1 . Commented Oct 9, 2015 at 12:13
  • works fine as i can see on first click only. can't replicate it. Commented Oct 9, 2015 at 12:21

2 Answers 2

5

UPDATE:

$scope.dataItems.push(data.value);    
console.log("Data VALUES: "+data.value);
});

$scope.$apply();

The file reader API will work asynchronously, outside of the angularjs "flow". Therefore, you have to make apply int he end of the onload function, like in the above sample.

OLD:

Are you using the angularjs $http service? Otherwise, when you get the data back, are you doing a scope.$apply to refresh with the new data?

Sign up to request clarification or add additional context in comments.

5 Comments

what? is this answer or you are commenting?
Created fiddle at: jsfiddle.net/mavdhana/u3zgrgcx/1 . As I am not using $http.
It's an answer, with whatever best answer I could give with came into my mind. The problem is that I don't have enough points to add comments, so I have to answer, and since I have to answer I have to suggest what I can think of that could be the problem. :/
@Dhana please check my answer again.
@rvalerio, Yes, your solution has worked fine. Thanks for your help !!
2

You need to add $scope.$apply(); at the end of loadFile method. Check this fiddle.

Tell me if works fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.