I am trying to do use the angular push function but it is not working.
I want to add strings (or objects) into an array.
I searched for basic examples here at Stack Overflow but I couldn't find it.
Can anyone correct my code or write a very basic example?
Here is my example.
This is the HTML code:
<form ng-controller="TestController as testCtrl ng-submit="testCtrl.addText(myText)">
<input type="text" value="Lets go">
<button type="button">Add</button>
</form>
This is the Java Script code:
(function() {
var app = angular.module('test', []);
app.controller('TestController', function() {
this.arrayText = {
text1: 'Hello',
text2: 'world',
}
this.addText = function(text) {
arrayText.push(this.text);
}
});
})();
this.arrayText
is an object, it has nopush
, and it's not the same as justarrayText
? – adeneo May 27 '15 at 13:56<form ng-controller="TestController as testCtrl ng-submit="testCtrl.addText(myText)">
Is this correct? missing a"
? (also, arrayText has an extra comma). – briosheje May 27 '15 at 14:00