petebacondarwin / ng1-component-router-demo

MIT License
30 stars 9 forks source link

passing data to component #6

Open ArniDzhan opened 8 years ago

ArniDzhan commented 8 years ago

I can pass hardcoded data to component

$routeConfig: [{
      path: '/record/:id/...',
      component: 'record',
      name: 'Record',
      data: 'pass to component'
    }]

The problem I encountered is that $routeConfig is run before controllers, canActivate etc. Would be useful to pass url param from parent route or some object with data required for that component, is there a way to do this?

winnemucca commented 8 years ago

Might help if you have a plunker. Wondering if $onInit might be something you are looking for.

ArniDzhan commented 8 years ago

Might help if you have a plunker. Wondering if $onInit might be something you are looking for

thanks @winnemucca but $onInit runs after $canActivate, so doesn't work for this case. It seems that the only place to do that is in on angular.module('app').run() forcing $rootRouter to run after a service is run. I suppose if I use a service and pass through a model which can later(on canActivate or routerOnActivate) be updated and will propagate. I will update when I try that approach.