I am making an angular controller and need to initialize an array with two empty objects so that two lines will appear on the screen and I need to initialize a new object in the array when a + button is clicked. I am unsure about how to go about doing this.
This is my best attempt:
var myApp = angular.module('myApp', []); myApp.controller('myController', ['$scope', '$q', function($scope, $q) { $scope.arr = [card('',''),card('','')]; $scope.addLine = function(index){ $scope.arr.push(card('','')); } $scope.removeLine = function(index){ $scope.arr.splice(index, 1); } }]); function card(term, definition){ this.term = term; this.definition = definition; }
[new card('',''), new card('','')]