Skip to content

States with both bindings and views properties should not validate #3340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kdbruin opened this issue Feb 17, 2017 · 4 comments
Closed

States with both bindings and views properties should not validate #3340

kdbruin opened this issue Feb 17, 2017 · 4 comments
Milestone

Comments

@kdbruin
Copy link

kdbruin commented Feb 17, 2017

[Using ui-router v1.0.0-rc1]

I have a 2-factor registration dialog that uses a parent state with two child states. Retrieving the user information in a resolve in the first child state and using a binding to rename the resolve doesn't seem to work.

function userRegistrationConfig($stateProvider, STATES)
{
  $stateProvider
    .state(STATES.REGISTRATION, {
      url: "/registration/:registrationID",
      template: "<div layout-fill ui-view='registration'></div>",
      redirectTo: STATES.REGISTRATION_START
    })

    .state(STATES.REGISTRATION_START, {
      url: "/start",
      views: {
        "registration": "userRegistration"
      },
      params: {
        registrationID: null
      },
      bindings: {
        user: "registrationInfo"
      },
      resolve: {
        registrationInfo: function (registrationService, $transition$)
        {
          return registrationService.getRegistrationInfo($transition$.params().registrationID);
        }
      }
    })

    .state(STATES.REGISTRATION_SMS, {
      url: "/sms",
      views: {
        "registration": "smsVerify"
      },
      params: {
        nextState: null
      }
    });
}

The above doesn't work. When I remove the bindings from the STATES.REGISTRATION_START state and change the registrationInfo to user it all works.

@christopherthielen
Copy link
Contributor

That is supposed to work, so this does look like a bug. Can you reproduce this a plunker for me?

@kdbruin
Copy link
Author

kdbruin commented Feb 19, 2017

I've created a pen for you. As it is now it shows the data. When the "userInfo" to "user" binding is enabled and the "userInfo" resolve is used instead of the "user" resolve the data will not show.

Link to the pen: http://codepen.io/kdbruin/pen/JEQYQX

@christopherthielen
Copy link
Contributor

Hi @kdbruin

I just realized why the problem. http://codepen.io/anon/pen/oZXgwO?editors=0010

bindings is a view property. You should not use the "$default" shorthand view properties (view properties on the state object) when separate views: {} block.

Since your state has a views block and a bindings block, it should not have passed validation. I'll mark this as a bug in the validation code.

You should either do:

state = {
  component: 'user',
  bindings: { user: 'userResolve' },
}

or

state = {
  views: {
    user: {
      component: 'user',
      bindings: { user: 'userResolve' },
    }
  }
}

@christopherthielen christopherthielen added this to the 1.0.0-rc.2 milestone Feb 26, 2017
@christopherthielen christopherthielen changed the title Bindings not working for child state States with both bindings and views properties should not validate Feb 26, 2017
@kdbruin
Copy link
Author

kdbruin commented Feb 26, 2017

Thanks for the clarification. I will make appropriate changes to my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants