[Chartjs]-Accessing returned data from a states resolve function

1👍

To access your resolved data you simply define them as bindings to your controller. Like you’ve already done with patent. Then you access them through your vm variable (or this).

angular.module('myApp').component('patent', {
    bindings: { 
        patent: '<' ,
        graph: '<'
    },
    templateUrl: '../templates/patents/list/patent-item.htm',
    controller: function() {
        var vm = this;

        vm.$onChanges = function(changeObj){
            if(changeObj.patent){
                console.log('I am your patent', vm.patent);
            }
            if(changeObj.patent){
                console.log('I am your graph', vm.graph);
            }
        }
    }
});

As @rrd suggests, you should guard your controllers against minification, but not only that, you should also guard your resolve functions from minification.

Like so:

resolve: {
    patents: ['patentsService', function(patentsService) {
        return patentsService.fetchAllPatents();
    }],
    graphs: ['patentsService', function(patentsService) {
        return  patentsService.fetchGraphData();
    }]
} 

1👍

As Vivz pointed out, injection into the controller should work, but you need to ensure to guard against minification issues:

angular.module('myApp').component('patent', {
  bindings: { 
    patent: '=' ,
  },
  templateUrl: '../templates/patents/list/patent-item.htm',
  controller: ['graph', function(graph) {
    var vm = this;

    //WHERE I NEED TO ACCESS THE RETURNED VALUE

  }]
});

Leave a comment