ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

beta-3 with angular 1.5.6 and higher doesn't bind component resolves

Open XplMarcel opened this issue 10 years ago • 3 comments

I decided to update angular from 1.5.5 to 1.5.8, but noticed that promises from resolves don't bind the promise result anymore. However, i noticed they are actually present in the $scope.$parent.$resolve if i check the $scope on my component.$onInit. After i did a rollback to angular 1.5.5 the bindings worked again.

State definition:

$stateProvider.state('dashboard', {
    url: '/dashboard',
    component: 'dashboard',
    resolve: {
       /* Makes sure the widgets for the current user are loaded */
       widgets: ['authenticationService', 'dashboardService', function (authenticationService, dashboardService) {
          return dashboardService.loadWidgetsAsync(authenticationService.user.id);
       }],
       /* Makes sure the app definitions are loaded */
       apps: ['appService', function (appService) {
         return appService.getAppDefinitionsAsync();
       }]
    }
});

Component definition:

angular.module('myApp')
  .component('dashboard', {
    bindings: {
      widgets: '<', // binding for widgets
      apps: '<' // binding for app definitions
    },
    controller: ['$scope', ' DashboardController],
    templateUrl: '/app/views/dashboard/dashboard.html'
});

XplMarcel avatar Oct 12 '16 07:10 XplMarcel

in angular 1.5 components, you should avoid using $scope. The resolves should be bound on the this object. For example:

function DashboardController() {
  console.log(this.widgets)
}

christopherthielen avatar Oct 12 '16 23:10 christopherthielen

heres a plunker http://plnkr.co/edit/AeBySYQSfoCCIe6dzVI8?p=preview

christopherthielen avatar Oct 12 '16 23:10 christopherthielen

Closing because I think the question is answered, and no response.

christopherthielen avatar Oct 26 '16 16:10 christopherthielen