Skip to content
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

ResolvePolicy NOWAIT - promise not injected as binding to component #3276

Closed
aj-dev opened this issue Jan 18, 2017 · 14 comments
Closed

ResolvePolicy NOWAIT - promise not injected as binding to component #3276

aj-dev opened this issue Jan 18, 2017 · 14 comments
Labels
Milestone

Comments

@aj-dev
Copy link
Contributor

aj-dev commented Jan 18, 2017

This is related to the previous issue I had #3243 using

resolvePolicy: {
    when: 'LAZY',
    async: 'NOWAIT'
}

The fix seems to be working fine when data promise is injected into controller defined on the state, but that's not the case when using Angular component's controller https://plnkr.co/edit/2EbaCl?p=preview

dataPromise resolve is correctly injected into onEnter hook but not as a binding to partial component's controller.

@christopherthielen christopherthielen added this to the 1.0.0-rc.2 milestone Jan 19, 2017
@christopherthielen
Copy link
Contributor

This one's a mystery to me. The value is on $resolve but it's not being bound to the input.

@kyse
Copy link

kyse commented Jan 30, 2017

Which version of angular are you using? Does this relate at all to the need to use $onInit to access bindings in the controller now in angular 1.6 by chance?

@aj-dev
Copy link
Contributor Author

aj-dev commented Jan 30, 2017

After some trial and error, I have discovered that the issue is caused by data prefix in resolve name, e.g. dataPromise. From Angular's perspective, it is the same as data-promise attribute from which the data prefix gets removed when creating the binding.

So the binding should be promise: '<' instead of dataPromise: '<' and component controller's $onInit() should have this.promise.then() instead of this.dataPromise.then().

Having said that, I think it's worth adding a few lines to the documentation, warning against use of the data prefix in resolve names when combined with Angular components. This might save everyone some precious time.

@christopherthielen
Copy link
Contributor

christopherthielen commented Jan 30, 2017

@aj-dev awesome! I think UI-Router can handle this by pre-prefixing data to the template if we find a resolve that starts with dataSomething or xSomething. Instead of generating data-something or x-something we can generage data-data-something and data-x-something.

@aj-dev
Copy link
Contributor Author

aj-dev commented Jan 31, 2017

@christopherthielen indeed, always pre-prefixing data sounds like the best solution! Are you still going to release this fix in RC-2?

@christopherthielen
Copy link
Contributor

Yes. this fix will be in the next release. (RC.2? final?)

@CarterLi
Copy link

CarterLi commented May 3, 2017

Just upgraded ui-router to 1.0.0. x-my-component broke my CSS files which expect an element named my-component

Any option reverts this to the old behavior?

@christopherthielen

@aj-dev
Copy link
Contributor Author

aj-dev commented May 3, 2017

@CarterLi you should not rely on custom component names crated by a 3rd party lib in your CSS. IDs and classes are the way to go.

@CarterLi
Copy link

CarterLi commented May 3, 2017

@aj-dev But I can't add IDs, classes to the generated element either.

I have to style it, which have no height, display: inline by default.

@aj-dev
Copy link
Contributor Author

aj-dev commented May 3, 2017

@CarterLi take a look at the feature request here #3385. That should solve your issue once implemented.

@CarterLi
Copy link

CarterLi commented May 3, 2017

No.

A component ( custom element ) should be self-contained. It should be able to style itself without expecting any additional code from its user.


For example:

A div have its own style display: block by default. Its users don't bother adding something like class="display-block"

@kaero598
Copy link

kaero598 commented May 3, 2017

The fix totally breaks routed components styling in Angular 1.x.

This is not the case for Angular 2 since we could write something like :host { <whatever styling applies to component itself> }. But Angular 1.x does not have such a feature and using direct component tag names in CSS is the only way of styling routed components.

I believe the fix should provide some configuration option to turn prefixing component tag names on or off.

@aj-dev
Copy link
Contributor Author

aj-dev commented May 3, 2017

I think what we need for NG1 is the ability to declare component attributes just like we can do with bindings:

.state('userlist', {
    url: '/users',
    component: 'users',
    // the `users` input binding on the component receives 
    // the `userlist` resolve value (from the state)
    bindings: {
        users: 'userlist'
    },
    // predefined component attributes for styling and other purposes
    attributes: {
        class: 'css-class',
        id: 'css-id'
    },
    resolve: {
        userlist: function(UserService) {
            return UserService.list();
        }
    }
});

@christopherthielen
Copy link
Contributor

@CarterLi I'm happy to add a feature flag for this. Please open a new issue

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

No branches or pull requests

5 participants