Routes cannot contain additional objects in angular 2.3.1 · Issue #13565 · angular/angular · GitHub

  • I edited the issue
  • marcuskrahl commented Dec 19, 2016 edited
  • DzmitryShylovich referenced the issue Dec 28, 2016
  • tbosch added a commit to tbosch/angular that referenced this issue Dec 27, 2016
  • Well I guess there is no real reason not to use the data property.

Contribute to angular development by creating an account on GitHub.

@bjschrijver: Creating object instances in your @angularjs 2.x route definitions?
You might hit this in the 2.3 upgrade (I did):

I’m submitting a … (check one with “x”)

Current behavior

with the stack trace:

of the passed variable which in this case is an object instance so fails.

This worked in 2.2.4 but fails with 2.3.1. It fails for a webpack build, I haven’t tried any other build tools.

Expected behavior

The user should be able to add arbitrary properties to route entries without causing compilation errors.

Minimal reproduction of the problem with instructions

Add an object instance to a route definition like:

see https://github.com/marcuskrahl/angular-bug-route-with-object-instance for an example repository

Workaround

If the object instance creation is replaced with a function call, the example works without any problems (but of course the access of the data has to be changed).

… data: { otherProperty: () => new SomeObject(), } …

What is the motivation / use case for changing the behavior?

You should be able to add application dependant information to routing entries.

Please tell us about your environment:

angular-cli changed to 2.3.1 runtime on Windows 7.

Also does not work on custom webpack build without angular-cli.

why don’t u use router data for arbitrary properties?

Well I guess there is no real reason not to use the data property. Since what I did is a usage error I might as well close this bug.

The problem apparently still exists when using router data for this information. I edited the issue accordingly

does it work for a simple object ?

data: { otherProperty: {}, }

It works with simple objects, but I have to use instances of concrete typescript objects for my use case.

@chuckjaz I would say it’s a compiler bug.

The angular CLI currently doesn’t support 2.3.1. We are working on a new release of the CLI that will support the up coming 2.4.0. I am keeping this bug open for now until we can verify that this is not an issue with 2.4.0 and the new CLI release.

This is not an issue with the cli because the same error exists in my main project which does not use angular cli at all. Just try it in any other project. The bug is triggered when an object instance is added to the route data and the class was imported into the file containing the route definition. Am 19. Dezember 2016 20:50:51 MEZ, schrieb Chuck Jazdzewski :

Pulling @tbosch.

is a directive and try to object its metadata. Instead of using its constructor it uses the instance, and fails.

Not sure if this is a blocker, but in my opinion people will be using instances. What’s weird to me is that we don’t respect the schema and look for directives everywhere.

To Tobias:

@marcuskrahl Acknowledged. Hans determined the same thing. @tbosch is not looking into it.

fields but using for example:

and this is causing issues. Not sure if this is a webpack thing or something else, this is the line where it falls over

@chuckjaz did you say @tbosch is not looking at it or did you mean now looking at it?

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Routes cannot contain additional objects in angular 2.3.1 · Issue #13565 · angular/angular · GitHub