1

Kinda new to angularjs. I have the following code and just wondering if someone can't enlighten me as to why my values aren't being persisted in there respective array

<script type="text/javascript">
'use strict';
var app = angular.module('app', ['appControllers']);
"use strict";
var appControllers = angular.module('app', []);
appControllers.controller('personController', ['$scope', '$http', function ($scope, $http) {

$scope.responses = [];
$scope.coaches = [];
$scope.athletes = [];
$scope.staff = [];

$scope.addCoach = function() {
var coach = $scope.coach;
$scope.coach = {}; // Do this to clean up the form fields
$scope.coaches.push(coach);
//$scope.responses.push(coaches); 
};

.....

$scope.addContact = function ($event) {

$event.preventDefault();
$scope.responses.push(coaches); 
console.log("inside this method");

}

So i take the list of coaches that have been added and am trying to push them further to the responses array. Everytime is hits this function of addContact or just pushing it from the original function it returns the responses array as empty. any insight?

2 Answers 2

3

You're trying to push coaches instead of $scope.coaches.

So this is what you should be writing:

$scope.responses.push($scope.coaches); 
Sign up to request clarification or add additional context in comments.

Comments

2

You did not define a variable with the name coaches. There is only $scope.coaches, which you should use at $scope.responses.push(coaches);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.