angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

State's data property not inherited #3577

Closed EmhyrVarEmreis closed 6 years ago

EmhyrVarEmreis commented 6 years ago

This is a:

My version of UI-Router is: 1.0.0-beta.9 (from uirouter/angular-hybrid: 3.1.7)

Bug Report

I have the following states:

{
    name:     'test',
    data:     {
        param2: 'value2'
    }
},
{
    name:   'test2',
    parent: 'test',
    url:    '/test',
    data:   {
        param1: 'value1'
    },
    views:  {
        '@': {
            component: TestComponent
        }
    }
}

And I have also this transition hook:

this.transitionService.onSuccess({to: '**'}, transition => {
    console.log(transition.to().data);
});

And the problem is that in console I see only { param1: 'value1'} insetad of { param1: 'value1', param2: 'value2'}. As far as i know, the data property from parent state should be inherited in child states, but it is not.

EmhyrVarEmreis commented 6 years ago

@sabousha I do not understand. It is not a bug? I think that according to docs It should behave as I expected.

sedkis commented 6 years ago

@EmhyrVarEmreis , I'm sorry -- it very well might be. I can't know without looking into it. I thought you were just being lazy. I've deleted my old post so not to clutter the thread.

christopherthielen commented 6 years ago

@EmhyrVarEmreis this data property is inherited using prototypal inheritance. This is working as expected, as far as I can tell. In the console, expand the proto property of the object and you should see the parent state's data.

Here's a plunker which demonstrates this: http://plnkr.co/edit/5D1qv4u2LCYlacIxByds?p=preview

screen shot 2017-12-20 at 3 44 00 pm