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.
-
I have created fiddle at: jsfiddle.net/mavdhana/u3zgrgcx/1Dhana– Dhana2015-10-09 12:13:02 +00:00Commented Oct 9, 2015 at 12:13
-
1can you show us what code you have?Jesse– Jesse2015-10-09 12:13:08 +00:00Commented Oct 9, 2015 at 12:13
-
I forgot to include fiddle in my question, I have created at: jsfiddle.net/mavdhana/u3zgrgcx/1 .Dhana– Dhana2015-10-09 12:13:48 +00:00Commented Oct 9, 2015 at 12:13
-
works fine as i can see on first click only. can't replicate it.Jai– Jai2015-10-09 12:21:05 +00:00Commented Oct 9, 2015 at 12:21
Add a comment
|
2 Answers
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?
5 Comments
Jai
what? is this answer or you are commenting?
Dhana
Created fiddle at: jsfiddle.net/mavdhana/u3zgrgcx/1 . As I am not using $http.
rvalerio
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. :/
rvalerio
@Dhana please check my answer again.
Dhana
@rvalerio, Yes, your solution has worked fine. Thanks for your help !!
You need to add $scope.$apply(); at the end of loadFile method.
Check this fiddle.
Tell me if works fine.