dman
dman

Reputation: 11064

Angular UI Router - Access Custom Data in Children's Resolve {}

How come this Inherited Custom Data data is not accessible in the child state main.loadbalancer.vips in the resolve: {} function hello?

angular.module("main.loadbalancer", ["ui.bootstrap", "ui.router"]).config(function($stateProvider) {
  return $stateProvider.state("main.loadbalancer", {
    data: { readonly : false },
    url: "device/:id",
    views: {
      "content@": {
        templateUrl: "loadbalancer/loadbalancer.html",
        controller: "LoadBalancerCtrl"
      }
    }
  }).state("main.loadbalancer.vips", {
    url: "/vips",
    templateUrl: "loadbalancer/vip-table.html",
    resolve: {
      hello: function(data) {
        console.log(data);
      }
    },
    controller: "VipListCtrl"
  })

Upvotes: 0

Views: 493

Answers (2)

Stone
Stone

Reputation: 2668

That data should be accessible in the $state object if you inject it ($state):

$state.$current.data.readonly

Upvotes: 1

dman
dman

Reputation: 11064

I had to use this.data...

  }).state("main.loadbalancer.vips", {
    url: "/vips",
    templateUrl: "loadbalancer/vip-table.html",
    resolve: {
      hello: function() {
        console.log(this.data);
      }
    }

Upvotes: 0

Related Questions