X Tutup
Skip to content

Alpha 35: Acessing RouteParam when no route parameter are provided produce exception #3755

@cghislai

Description

@cghislai

I have routes defined as

{path: '/items/edit/', component: EditProductView, as: 'itemsEditNew'},
{path: '/items/edit/:id', component: EditProductView, as: 'itemsEdit'},

In EditProductView, I inject RouteParams in the constructor

import {RouteParams} from 'angular2/router';
// ...
constructor(routeParams:RouteParams) {
        var itemIdParam;
        if (routeParams != null) {
            itemIdParam = routeParams.get('id');
        }
        this.itemId = parseInt(itemIdParam);
        if (isNaN(this.itemId)) {
            this.itemId = null;
        }
    }

This worked fine in alpha33.
In alpha35, this works fine as long as a route parameter is provided. If none are provided (for exmple, following a router-link to /itemsEditNew), then an exception is thrown:

EXCEPTION: Error during instantiation of EditProductView!.
angular2.js:13030 ORIGINAL EXCEPTION: TypeError: Cannot read property 'hasOwnProperty' of null
angular2.js:13030 ORIGINAL STACKTRACE:
angular2.js:13030 TypeError: Cannot read property 'hasOwnProperty' of null
    at Function.execute.StringMapWrapper.get (angular2.js:6299)
    at RouteParams.execute.RouteParams.get (router.js:4906)
    at new EditProductView (editView.ts:79)
    at execute.ReflectionCapabilities.factory (angular2.js:12767)
    at Injector.execute.Injector._instantiate (angular2.js:5952)
    at Injector.execute.Injector._new (angular2.js:5883)
    at InjectorInlineStrategy.execute.InjectorInlineStrategy.instantiateBinding (angular2.js:5672)
    at ElementInjectorInlineStrategy.execute.ElementInjectorInlineStrategy.hydrate (angular2.js:17257)
    at ElementInjector.execute.ElementInjector.hydrate (angular2.js:16910)
    at execute.AppViewManagerUtils._hydrateView (angular2.js:15038)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup