0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

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.