Reputation: 97
i am updating a SPA but i have a problem i want to display the name of the classes but nothing appears here is the code where i have a problem with maybe i am missing something:
$scope.open = function (classes) {
$log.info("classes",classes);
var modalInstance = $modal.open({
templateUrl: 'classes.html',
controller: 'ModalClassesInstanceCtrl',
resolve: {
info: function () {
var info = {};
info['name']= classes.name;
$log.warn("classes info",info);
return info;
}
}
});
what i got in console
$log.info("classes",classes);
show that i have 5 classes like this
classes [Object, Object, Object, Object, Object]
if i click on any object it shows all the data about that object including the class name for example clicking the first object will show the following data
1: Object $$hashKey: "object:13" id: 4 level: "4" name: "fox" year: "2015/2016"
but
$log.info("classes info",info);
only show class info Object {name: undefined}
please can u check weather i have something wrong in this code
Upvotes: 0
Views: 19
Reputation: 983
Look carefully at this line:
info['name']= classes.name;
. classes
is an array of objects, not an object with name
property - that's why you get undefined. If you want to display a class name, you need to refer to an object inside an array, e.g. classes[0].name
. If you want to display all classes' names, you should iterate over them and join the names into one string.
Upvotes: 1