GithubHelp home page GithubHelp logo

Comments (14)

tonimoeckel avatar tonimoeckel commented on April 26, 2024 1

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.

from angular.

aitboudad avatar aitboudad commented on April 26, 2024 1

It should be solved soon see angular/angular@bd64ab5

from angular.

aitboudad avatar aitboudad commented on April 26, 2024

angular/angular-cli#4301

from angular.

christopherthielen avatar christopherthielen commented on April 26, 2024

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

from angular.

aitboudad avatar aitboudad commented on April 26, 2024

another approach is to pass the inputs through state config:

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

from angular.

christopherthielen avatar christopherthielen commented on April 26, 2024

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: ...
            },
        ],
    },

from angular.

aitboudad avatar aitboudad commented on April 26, 2024

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)

from angular.

christopherthielen avatar christopherthielen commented on April 26, 2024

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');
  }
}

from angular.

aitboudad avatar aitboudad commented on April 26, 2024

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 })

from angular.

christopherthielen avatar christopherthielen commented on April 26, 2024

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;
}

from angular.

aitboudad avatar aitboudad commented on April 26, 2024

it seems not possible :(

from angular.

christopherthielen avatar christopherthielen commented on April 26, 2024

@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()

from angular.

christopherthielen avatar christopherthielen commented on April 26, 2024

@aitboudad that's very promising!

from angular.

christopherthielen avatar christopherthielen commented on April 26, 2024

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.

from angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.