Skip to content

Add to Breaking Changes: stateConfig.views[0].resolve object is never used #3208

@Maximaximum

Description

@Maximaximum

While updating from ui-router v0.3.0 to v1.0.0-beta.3 I've experience the following issue.

With v0.3.0, I was using view resolves like this:
$stateProvider

     $stateProvider
        .state('_.shop.search.item', {
          url: '/item/{itemId:int}',
          views: {
            "itemView@_.shop": {
              templateUrl: 'templates/shop/shop-item/shop-item.html',
              controller: 'ShopItemController',
              resolve: {
                product: function (server, $stateParams) {
                  return server["Shop/GetProductDetails"]($stateParams.itemId).then(function (response) {
                    return response.data;
                  })
                },
                productImages: function (server, $stateParams) {
                  return server["Shop/GetProductImages"]($stateParams.itemId).then(function (response) {
                    return response.data;
                  });
                }
              },
            }
          }

The ShopItemController looks like this:

.controller('ShopItemController', function ($scope, product, productImages, $anchorScroll, server, $compile, $interpolate, toaster, $stateParams, $state) {
}

After the update, I was getting "Unknown provider: productProvider <- product <- ShopItemController".

I've fixed this by moving the resolve property from the view object to the state object:

      $stateProvider
        .state('_.shop.search.item', {
          url: '/item/{itemId:int}',
          resolve: {
            product: function (server, $stateParams) {
              return server["Shop/GetProductDetails"]($stateParams.itemId).then(function (response) {
                return response.data;
              })
            },
            productImages: function (server, $stateParams) {
              return server["Shop/GetProductImages"]($stateParams.itemId).then(function (response) {
                return response.data;
              });
            }
          },
          views: {
            "itemView@_.shop": {
              templateUrl: 'templates/shop/shop-item/shop-item.html',
              controller: 'ShopItemController'
            }
          }
        });

I've figured out how to fix this issue myself, but I guess it would be helpful for others if you could add this issue to the Breaking Changes section of the UI Router migration guide (https://ui-router.github.io/guide/ng1/migrate-to-1_0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions