Skip to content

1.0 ComponentProvider? (ng1) #2995

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
patlux opened this issue Sep 14, 2016 · 7 comments
Closed

1.0 ComponentProvider? (ng1) #2995

patlux opened this issue Sep 14, 2016 · 7 comments

Comments

@patlux
Copy link

patlux commented Sep 14, 2016

Hello,

is there something like a 'ComponentProvider' to give a view dynamically a component like with ControllerProvider?

e.g.:

componentProvider: function(MyResolveData, $transition$) {
  if (MyResolveData.foo) {
    return "Foo"
  } else if ($transition$.to().name === 'bar') {
    return "Bar";
  } else {
    return MyResolveData.component;
  }
}

My current workaround is something like this:

templateProvider: function(MyResolveData) {
  return "<" + MyResolveData.component + "></" + MyResolveData.component + ">";
}

But with my workaround, it's not possible to use the Methods from Ng1Controller.

@patlux patlux changed the title 1.0 ComponentProvider? 1.0 ComponentProvider? (ng1) Sep 14, 2016
@christopherthielen
Copy link
Contributor

There is not, but it seems like there should be. I'd be open to a PR which implements this.

I'd just need:

  • a unit test or three
  • docs for componentProvider

@sarahpads
Copy link
Contributor

sarahpads commented Nov 7, 2016

Hi guys,

I'm looking at how this feature could be implemented. I'm new to the code base and would really appreciate any guidance.

Am I correct in understanding that the component logic would have to be moved from the ng1ViewsBuilder (statebuilders/views.ts:24) into the Ng1ViewConfig class definition (statebuilders/views.ts:123)? I came to this understanding because the PathNode information is available in the class definition.

Am I completely off the mark?

@christopherthielen
Copy link
Contributor

christopherthielen commented Nov 7, 2016

@sarahpads happy to provide any insights I can.

I think the block of code after this comment:
// Dynamically build a template like "<component-name input1='::$resolve.foo'></component-name>"
probably belongs in template factory.

It could be named fromComponent, and then have a provider version called fromComponentProvider.

The current fromProvider function shows how to inject a provider function with the proper resolve context (this make sure it can inject the right $transition$, etc). That function can probably be reused, extracted as a standalone or static fn.

@sarahpads
Copy link
Contributor

Hi again,

I have put together a pull request that addresses this thread: #3165.

Please let me know if there are any improvements I can make or if I've stomped over some coding conventions.

Thanks!
Sarah

@mackelito
Copy link

mackelito commented Nov 22, 2016

What are the benefits of routing to the component directly vs using a template like

<component-name input1='::$resolve.foo'></component-name>

?

@christopherthielen
Copy link
Contributor

@mackelito it's just sugar for building the template (like your example). It can reduce boilerplate, and follows the same mental model as the other component based ui-routers (ng2 and react)

In the future there may be other benefits for ng1, such as propagating callback bindings from the parent ui-view tag to the child component.

@christopherthielen
Copy link
Contributor

Closed by 4b58360 / #3165

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

4 participants