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

Angular 8 support? #38

Open
Figments opened this issue Oct 21, 2019 · 7 comments
Open

Angular 8 support? #38

Figments opened this issue Oct 21, 2019 · 7 comments

Comments

@Figments
Copy link

Hello.

I'm currently getting an error trying to implement Toppy in an Angular 8 SPA, specifically in regards to the @ViewChild decorator.

On the following piece of code:

@ViewChild('login', { read: typeof ElementRef, static: true }) login: ElementRef;

The error outputs as:

ERROR in src/app/app.component.ts(12,31): Error during template compile of 'AppComponent'
  Expression form not supported.

I believe it might have to do with a lack of support for Angular 8? Though I'm not entirely sure. Any update on this would be appreciated.

@buseodaci
Copy link

Hi,
I prepared an example using Angular 8. I had to made changes using this package. I hope it helps but u can see here.
https://angular-bdhgvc.stackblitz.io
For code :
https://stackblitz.com/edit/angular-bdhgvc

@Figments
Copy link
Author

I can't seem to open either link. The first gets stuck infinitely attempting to start the dev server, while the second nets a 404.

@Figments
Copy link
Author

It appears like it's having the same issue. Could you maybe post the code in a Gist or Pastebin? Don't know why stackblitz is giving me issues.

@buseodaci
Copy link

buseodaci commented Oct 22, 2019

Here you go : https://github.com/buseodaci/toppy-angular

@Figments
Copy link
Author

Awesome. That link works. I'll report back if I can get it working.

Thanks! :D

@buseodaci
Copy link

I hope it helps.

@Figments
Copy link
Author

Figments commented Oct 23, 2019

Well, the good news is the Expression form not supported error is now gone. However, activating the button results in an undefined is not an object error.

The code in question:

export class AppComponent {
  @ViewChild("login", { read: ElementRef, static: true })
  login: ElementRef;
  overlay: ToppyControl;
  overlayControl: boolean;

  title = 'Offprint';
  currentUser: User;

  searchForm = new FormGroup({
    query: new FormControl('', Validators.required)
  });

  constructor(private authService: AuthService, private _toppy: Toppy) {
    this.authService.currentUser.subscribe(x => this.currentUser = x);
  }

  ngOnInit() {
    this.overlayControl = false;
    const position = new RelativePosition({
      placement: OutsidePlacement.BOTTOM_RIGHT,
      src: this.login.nativeElement
    });
    this.overlay = this._toppy
      .position(position)
      .content(`<div>any HTML content</div>`, { hasHTML: true })
      .create();
  }

  open() {
    this.overlayControl = true;
    this.overlay.open();
    console.log("opened");
  }

  close() {
    this.overlayControl = false;
    this.overlay.close();
    console.log("closed");
  }

  controlLoginMenu() {
    if (this.overlayControl == false) {
      this.open();
    } else {
      this.close();
    }
  }
}

Any help would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants