I am a javascript noob so i dont understand why in the code below the author uses Avengers.cast instead of just Avengers?
var myApp = angular.module('myApp', []);
myApp.factory('Avengers', function() {
var Avengers = {};
Avengers.cast = [{
name: "Robert Downey Jr.",
character: "Tony Stark / Iron Man"
}];
return Avengers;
})
function AvengersCtrl($scope, Avengers) {
$scope.avengers = Avengers;
}
var Avengers = {};
This means: create a new object and refer to it by the variable Avengers
Avengers.cast = [{
name: "Robert Downey Jr.",
character: "Tony Stark / Iron Man"
}];
This means: the object just created now has a property called cast
. This is an Array and contains exactly one object (with two properties with String values).