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

[@angular/cli] input decorator is removed when using the AoT build #36

Closed
aitboudad opened this issue Feb 2, 2017 · 14 comments
Closed
Labels
Milestone

Comments

@aitboudad
Copy link
Contributor

The resolve data doesn't supplies component inputs anymore in AoT build since the last version of @angular/cli as it remove all angular decorators in order to have less bundle size.

I propose to introduce custom decorator for resolve data:

@Component({ ... })
export class App {
    @Resolve() foo;
}
@aitboudad
Copy link
Contributor Author

angular/angular-cli#4301

@tonimoeckel
Copy link

Great idea! I'm facing the same problem on my project. However I gave your Idea a try.
See my commit: Resolve Decorator
But I got stuck. The AoT compiler prints the annoying error:

ERROR in Error encountered resolving symbol values statically. Calling function 'makePropDecorator', function calls are not supported.

I don't know how to get rid of this. I tried to export and wrap the function call, without any success.
@aitboudad I'd appreciate if you could have a look on it.

@christopherthielen christopherthielen added this to the 1.0.0-beta.5 milestone Feb 4, 2017
@christopherthielen
Copy link
Member

I really want to use @Input() because it allows components to be agnostic towards being routed or not routed.

@aitboudad
Copy link
Contributor Author

another approach is to pass the inputs through state config:

    {
        name: 'app',
        component: App,
        resolve: [
            {
-               token: 'app',
+               input: 'app',
                deps: ...
            },
        ],
    },

@christopherthielen
Copy link
Member

another approach is to pass the inputs through state config:

That would not allow resolves declared on a parent state to be bound to a (routed) child component. It would have to be mapped on the view level. We already have the bindings: property on a view declaration which serves this purpose. However, making it mandatory would introduce a lot of boilerplate.

    {
        name: 'app',
        component: App,
+        bindings: { app: 'app' },
        resolve: [
            {
               token: 'app',
                deps: ...
            },
        ],
    },

@aitboudad
Copy link
Contributor Author

AOT already introduced a lot of boilerplate :) so I'm ok with the bindings: property as I think the bundle size is important too (in my case removing decorators shrunk the bundle size by ~170 Kb)

@christopherthielen
Copy link
Member

christopherthielen commented Feb 10, 2017

I'd like to point out that in 1.0.0-beta.4 the only workaround is to inject the resolves into the component constructor:

@Component({
})
export class MyComponent {
  constructor(@Inject('myResolve') public resolveData: any) {
  }
}
  • or -
@Component({
})
export class MyComponent2 {
  public myResolve: any;
  constructor(transition: Transition) {
    this.myResolve = transition.injector().get('myResolve');
  }
}

@aitboudad
Copy link
Contributor Author

since bindings is implemented what do you think about adding a new option autoBindings through the config part which will pass all resolved values into the component if the property have the same name of resolved value.

UIRouterModule.forRoot({ autoBindings: true })

@christopherthielen
Copy link
Member

I've been considering a similar thing, but how can you tell if a newly constructed component has a property or not?

class FooComponent {
   someInput: string;
}

@aitboudad
Copy link
Contributor Author

it seems not possible :(

@christopherthielen
Copy link
Member

@aitboudad For now I'm going to use your original idea of a Decorator like @ResolveData() resolveInput

I don't like not using @Input(), but this seems like a simple way to manage until Angular comes up with a solution for exposing metadata to for third parties, when we will remove @ResolveData and have users switch back to @Input()

@aitboudad
Copy link
Contributor Author

It should be solved soon see angular/angular@bd64ab5

@christopherthielen
Copy link
Member

@aitboudad that's very promising!

@christopherthielen
Copy link
Member

christopherthielen commented Mar 29, 2017

I am going to remove the ResolveData decorator before releasing beta.5 which will support angular 2.x I will then release beta.6 using the inputs as exposed in that commit.

christopherthielen added a commit that referenced this issue Apr 22, 2017
christopherthielen added a commit that referenced this issue Apr 27, 2017
…n AoT

When angular started stripping reflect metadata for AoT, it broke our ability to introspect a component to determine what inputs it had.
In this commit angular/angular@bd64ab5 the inputs/outputs are added to the component factory, and we now have a public API to introspect component inputs.

Closes #94
Closes #89
Closes #36
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

3 participants