how to display object

Issue

I am using Restangular and PHP REST service
I am able to fetch data from PHP REST via calling from RestAngular.

My code looks like

angular
    .module("classManagement")
    .controller('ClassSectionListCtrl', function (Restangular) {
        var vm = this;
         vm.currentYr = Restangular.one("currentYear").getList().$object;
    })

currentYr return structure is as following

[{"currentYear":"2015"}]

How I can display output on console for return object?
I tried doing

console.log(vm.currentYr);

it return [] on console.

console.log(vm.currentYr.currentYear); print undefined on console.

My end target is to store currentYear for exampe 2015 in a variable.

Any suggestion. Thanks

Solution

Does this get you close?

       angular
        .module("classManagement")
        .controller('ClassSectionListCtrl', function (Restangular) {
            var vm = this;
            Restangular.all('currentYear').getList()
                .then(function(currentYears) {
                  vm.currentYr = currentYears[0].currentYear;
                  console.log(vm.currentYr);
                }
       })

Answered By – Marcidius

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.