demo-apps
demo-apps copied to clipboard
Angular demo could have simpler strategy
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 👍