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

`setOrientation()` causes `ExpressionChangedAfterItHasBeenCheckedError` #35

Open
rynop opened this Issue Jan 17, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@rynop
Copy link

rynop commented Jan 17, 2019

Strange one here. iOS. "nativescript-angular": "~7.1.0", "nativescript-orientation": "~2.2.1"

landscape.component.ts:

...
  constructor(
    private route: ActivatedRoute,
    private page: Page,
    private routerExtensions: RouterExtensions
  ) {
    this.page.actionBarHidden = true;
  }

  ngOnInit() {
    this.id = this.route.snapshot.params['id'];
    orientation.setOrientation('landscape', false);
 }

my landscape.component.html is completely empty.

the LandscapeComponent is loaded via navigation from another component. The onCreate() method is called from a (tap)="onCreate() button press:

  async onCreate() {
    try {
      const item = await this.createItem();
      console.log(`Created`, item);

      this.routerExtensions.navigate(['../landscape', item.id], {
        clearHistory: true
      });
    } catch (error) {
      console.error('Problem creating', error);
    }
  }

If I comment out orientation.setOrientation() I don't get the error.

Any ideas? FWIW it still flops the screen orientation to landscape.

@rynop

This comment has been minimized.

Copy link
Author

rynop commented Jan 21, 2019

The workaround I found is to add it into ngAfterViewInit() like so:

  ngAfterViewInit() {
    orientation.setOrientation('landscape', false);
    orientation.disableRotation();
  }

Putting it in ngOnInit() will cause Zone view update problems, I think due to the Error preventing further processing. It still throws the error, so if you have other logic in ngAfterViewInit() this hack may not work for you.
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment