简体   繁体   中英

Angular UI-Router Overwrite Resolve in Child States

I'm running into the issue, that I have the same resolve function in parent & child states - and depending on the child state, i would like to have it return a different value.
Somehow, instead of overwriting the implementation for it, it simply just takes the behavior from the parent state.

.state('wines', {
    url: '/wines',
    templateUrl: 'partials/products/index',
    controller: 'cwProductsController',
    resolve: {
      merchandiseView: function() {
        return "featured";
      }
    }
  }).state('wines.featured', {
    url: "/featured",
    templateUrl: 'partials/products/index',
    controller: 'cwProductsController',
    resolve: {
      merchandiseView: function() {
        return "featured";
      }
    }
  }).state('wines.curatorsChoice', {
    url: "/curators-choice",
    templateUrl: 'partials/products/index',
    controller: 'cwProductsController',
    resolve: {
      merchandiseView: function() {
        return "curators-choice";
      }
    }
  }).state('wines.stillAvailable', {
    url: "/still-available",
    templateUrl: 'partials/products/index',
    controller: 'cwProductsController',
    resolve: {
      merchandiseView: function() {
        return "still-available";
      }
    }

  });

Here, it always keeps on returning "featured", even when visiting wines/still-available , where I expect merchandiseView to be "still-available".

This is my controller:

angular.module('clubwApp').controller('cwProductsController', [
  '$scope', 'cwProduct', '$stateParams', 'merchandiseView', function($scope, cwProduct, $stateParams, merchandiseView) {
    console.log(merchandiseView);
    $scope.wines = cwProduct.available();
    return $scope.merchandiseView = angular.copy(merchandiseView);
  }
]);

Is there a way, how i can overwrite this?

  • Attach you specific data to the data state property instead of the resolve .
  • At controller initialization time read $state.current.data from the $state injectable.

This is apparently an issue (up until 0.2.15).
Here is a hacky solution to the problem: http://plnkr.co/edit/j1wCThlv1uczlX7d5cdg?p=preview the resolve: {test: {this.data.someObject}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM