demo-apps icon indicating copy to clipboard operation
demo-apps copied to clipboard

Angular demo could have simpler strategy

Open jrodl3r opened this issue 3 years ago • 0 comments

Why not use this approach (until a proper Angular-specific package arrives)?

  • include the JS files in /assets/js/
  • add JS files to angular.json (projects » architect » build » options » scripts)
  • add moralisAppId + moralisUrl to environments
  • setup app.component.ts:
import { Component } from '@angular/core';
declare const Moralis: any;
export class AppComponent {
  constructor() {
    Moralis.initialize(environment.moralisAppId);
    Moralis.serverURL = environment.moralisUrl;
  }

  connect(): void {
    Moralis.Web3.authenticate().then(function (user:any) {
      console.log(user.get('ethAddress'));
    });
  }
}
  • add button to app.component.html: <button (click)="connect()">Connect</button>

Seems a lot easier, less confusing than trying to get a node script to run in Angular 11+ without ejecting Webpack. Let me know what you think 👍

jrodl3r avatar Jul 10 '21 21:07 jrodl3r