question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router: property 'parentView' of undefined when missing selector in nested router

See original GitHub issue

I know this is being tracked here https://github.com/angular/angular/issues/1662, but I didn’t want to contaminate that thread with this issue.

From the issue referenced I understand that @Component without a selector is valid, so this works (I tried it and it does)

@Component()
@View({
  template : ``
})
@RouteConfig([
  new Route({path:'test', component: AnotherComponent, as :'test'})
])
class NestedRouter {}

@Component({ selector: 'hello' })
@View({
    template: `<router-outlet></router-outlet>`,
    directives : [RouterOutlet]
})
@RouteConfig([
  new Route({path:'/nested/...', component : NestedRouter, as : 'nested'})
])
class ...

But personally I’m too used to use selectors for components, so at first I tried adding a selector and I forgot to specify one

@Component({selector:''}) // <-- Empty selector, silly me!
@View({
  template : ``
})
@RouteConfig([
  new Route({path:'test', component: AnotherComponent, as :'test'})
])
class NestedRouter {}

@Component({ selector: 'hello' })
@View({
    template: `<router-outlet></router-outlet>`,
    directives : [RouterOutlet]
})
@RouteConfig([
  new Route({path:'/nested/...', component : NestedRouter, as : 'nested'})
])
class ...

in the latter case it throws this error message :

EXCEPTION: TypeError: Cannot read property 'parentView' of undefined
angular2.dev.js:22746 STACKTRACE:
angular2.dev.js:22746 TypeError: Cannot read property 'parentView' of undefined
    at execute.AppViewManager.getComponent (angular2.dev.js:26763)
    at angular2.dev.js:17442
    at Zone.run (angular2.dev.js:136)
    at Zone.execute.$__3._createInnerZone.zone.fork.fork.$run [as run] (angular2.dev.js:16756)
    at zoneBoundFn (angular2.dev.js:109)
    at lib$es6$promise$$internal$$tryCatch (angular2.dev.js:1391)
    at lib$es6$promise$$internal$$invokeCallback (angular2.dev.js:1403)
    at lib$es6$promise$$internal$$publish (angular2.dev.js:1374)
    at angular2.dev.js:187
    at execute.$__3._createInnerZone.zone.fork.fork.$scheduleMicrotask.microtask (angular2.dev.js:16782)

Adding a selector, or just removing everything inside @Component make everything works again.

Plnkr reproducing : http://plnkr.co/edit/SAXClK?p=preview

If this case is also being attacked in the issue referenced please close.

PS: Using alpha36

Edit plnkr updated to a54

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arloduffcommented, Nov 1, 2016

The error Uncaught (in promise): TypeError: Cannot read property 'visitExpression' of undefined still comes up sometimes, and seems to be related to the router. I just got it because of a stray comma at the end of one of my routes:

{ path: 'foo', outlet: 'modal', component: FooComponent },,
0reactions
angular-automatic-lock-bot[bot]commented, Sep 10, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In nested router, I want the parent router to disappear when I ...
For this I suggest using layout components that render the UI and layout as you desire and renders nested Route components into an...
Read more >
Top 18 Most Common AngularJS Developer Mistakes - Toptal
When I am writing this, the stable Angular is 1.3.15, and ui-router rocks. The main reasons: awesome state nesting; route abstraction; optional and...
Read more >
Framework7 Release Notes
New currentPageEl router property that points to current page HTMLElement. Improved routable tabs support for different routes but with same tab IDs; Improved ......
Read more >
Joint API - version 3.6 - JointJS
Expects a selector. A change in the cell's magnet affects the following characteristics of the cell view: link anchor; link connection point; connector;...
Read more >
Documentation - Ampersand.js
And it will create the properties in the JSON object as model properties. Don't worry, nothing will be overwritten unless you use the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found