toddmotto / angularjs-styleguide

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

The way to pass reference to event through the route config #110

Closed michalpanek closed 8 years ago

michalpanek commented 8 years ago

I have that situation:

Route config from statefull route component:

.state('conferences.conferencesList', {
        url: '/list',
        component: 'conferenceList',
        params: {
          conferencesList: undefined,
          onAddConference: undefined
        },
        resolve: {
          conferencesList: ($stateParams) => $stateParams.conferencesList,
          onAddConference: ($stateParams) => $stateParams.onAddConference
        }

and I have stateless component, which is children component for statefull component:

let conferenceListComponent = {
  bindings: {
    conferencesList: '<',
    onAddConference: '&'
  },
  template,
  controller
};

where onAddConference is a event to fire up to statefull parent component by stateless component (conferenceList in my example) How Can I pass to bindings of stateless component "reference" to function from my statefull component ? How can I do this in route configuration ?

I tried send "reference" to function by

 $state.go('somestate', ({
someBindings: something,
someEvent: this.someFunction
}); 

but I got a error message:

TypeError: Cannot read property '1' of null(…)

Is there a way to solve this issue, or am I entirely wrong ?

michalpanek commented 8 years ago

Thanks Todd for answered me in Disqus.

The js object must be passed through angular ui-router params with bindings inside, because of that js not really supporting passing variables by references, and when simple value, or function is passed by ui-router params, there is no possibility that bindings will be updated after changed in route component parent.

Please, correct me if I am wrong.

toddmotto commented 8 years ago

Hey @michalpanek did you fix this? Sorry slipped checking this one. If you're still having issues can you drop a jsfiddle of the code and reopen :)

michalpanek commented 8 years ago

Yea, already I found the solution: https://github.com/angular-ui/ui-router/issues/2888#issuecomment-242850953. but thanks:)