toddmotto / angularjs-styleguide

AngularJS styleguide for teams
https://ultimateangular.com
5.96k stars 700 forks source link

Using ui-router 0.3.x (stable) #54

Closed dgsmith2 closed 8 years ago

dgsmith2 commented 8 years ago

@toddmotto, for developers, such as myself, who aren't comfortable moving forward with an alpha release of ui-router, there is an alternative route-to-component approach. Starting with 0.3.0 a developer now has access to $resolve. While it requires being more verbose, it offers the following approach:

const todo = angular
  .module('todo', [])
  .component('todo', TodoComponent)
  .service('TodoService', TodoService)
  .config(($stateProvider, $urlRouterProvider) => {
    $stateProvider
      .state('todos', {
        url: '/todos',
        // full component html with binding attributes
        template: '<todo todo-data="$resolve.todoData"></todo>',
        resolve: {
          todoData: PeopleService => PeopleService.getAllPeople();
        }
      });
    $urlRouterProvider.otherwise('/');
  })
  .name;
toddmotto commented 8 years ago

Yeah! This is an alternative (and super easy upgrade too). Stable for the component routing won't be too far away so makes sense to mention it now to prepare. The alpha is super stable btw too!