im sure im missing something probably very basic but cant seem to wrap my head around this issue. I am simple trying to push an object into a scope array on click. I am currently getting error: TypeError: Cannot read property 'push' of undefined(…)
Heres an example of what I got so far:
var app = angular.module('myApp', []);
app.factory('MyService', function($http, $q, $timeout){
var My_Stored_Data = {}
return {
template: function(){
var template = { data1: "", data2: "", data3: "", data4: "" }
return template
}
}
});
Here is the controller:
app.controller('MyController', function ($scope,$q,MyService) {
$scope.Main_scope = {};
$scope.add_new_object = function(){
$scope.Main_scope.My_array.push(MyService.template());
//This give an error TypeError: Cannot read property 'push' of undefined(…)
}
});
Anyone have anyidea what im missing?