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

ERROR TypeError: _this._focusMonitor.monitor #11396

Closed
ThePatzen opened this issue May 18, 2018 · 6 comments
Closed

ERROR TypeError: _this._focusMonitor.monitor #11396

ThePatzen opened this issue May 18, 2018 · 6 comments
Assignees
Labels
P4 A relatively minor issue that is not relevant to core functions

Comments

@ThePatzen
Copy link

Bug, feature request, or proposal:

Bug

What is the current behavior?

I use Angular Universal with Angular 6.

On SSR i get the following error:
ERROR TypeError: _this._focusMonitor.monitor is not a function at MatAnchor.MatButton [as constructor] (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:176122:29) at new MatAnchor (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:176219:23) at createClass (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:14025:20) at createDirectiveInstance (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:13906:20) at createViewNodes (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:15128:36) at callViewAction (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:15444:13) at execComponentViewsAction (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:15363:13) at createViewNodes (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:15156:5) at Object.createEmbeddedView (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:15036:5) at TemplateRef_.createEmbeddedView (/home/mylehre_e-mx_at/mylehre/frontend/dist/server.js:13621:38)

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular = 6.0.2,
Material = 6.0.2
OS = Ubuntu 16.04
TypeScript = 2.7.2

@fvoska
Copy link

fvoska commented May 24, 2018

This seems to be an issue with the way FocusMonitor is provided: https://github.com/angular/material2/blob/37193d823bf0ca205e187273af80c4597b8f2d86/src/cdk/a11y/focus-monitor/focus-monitor.ts#L40

In Angular 6 there is a new way of providing services, by using treeshakeable operator @Injectable({providedIn: 'root'}). This works fine in the browser. However, it does not seem to work correctly at all times with lazy-loaded modules and SSR / universal.

Temporary solution is to provide FocusMonitor in your app manually for server module:

@NgModule({
  imports: [
    ...
  ],
  providers: [
    FocusMonitor,
  ],
  bootstrap: [...],
})
export class AppServerModule { }

Providing it in AppServerModule is enough, there is no need to provide it in AppModule as it works fine in browser.

@fvoska
Copy link

fvoska commented May 24, 2018

Possibly related to this issue: angular/angular#23715

@anymos
Copy link

anymos commented May 29, 2018

Great, thank you fro the workaround, It would have take me hours to find it out !

@jelbourn jelbourn added the P4 A relatively minor issue that is not relevant to core functions label May 31, 2018
@anymos
Copy link

anymos commented Jun 6, 2018

More on this issue, I have added the workaround. Strangely enough if I request / before the other url that is dynamically rendered and need the fix, the error is shown. If I do the opposite no error.

Just in case that it can be useful

@jelbourn
Copy link
Member

Duplicate of #11603

@jelbourn jelbourn marked this as a duplicate of #11603 Jul 24, 2018
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

4 participants