Hi,
I'm rather new to AngularJS and JavaScript, and I'm in the process of
learning them. So I was tinkering around a little bit trying to understand
different concepts and this is one that's driving me crazy. I'm calling the
addcomment() function from a html file. The function gets called, but
everytime i want this code to display:
<p ng-repeat="x in messages">{{x}}<br></p>
It displays to me only one "Hi"
I want a new "hi" to be pushed into my array everytime I call the function
from the HTML file. That is, if the function addcomment() has been called 5
times, then I want 5 "hi" in my array called messages[]. It seems to me
that everytime I call the function, the array gets reinitialised to empty
array. How do I go around this?
This is the code:
.controller('Ctrl',function($scope){
$scope.messages=[""];
$scope.addcomment = function(){
$scope.messages.push("Hi");
}
And this is how I'm going about with the HTML:
<button ng-click="addcomment()">Submit</button>
<p ng-repeat="x in messages">{{x}}
<br>
</p>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.