Aurelia CLI & TypeScript & MomentJS

前端 未结 2 1749
一整个雨季
一整个雨季 2021-01-14 04:11

I\'m not getting Aurelia (CLI) & TypeScript & MomentJS to work together. I\'ve seen solutions for Aurelia & Moment problems but they don\'t use the Aurelia CLI.

2条回答
  •  误落风尘
    2021-01-14 04:18

    Update

    This doesn't actually work. Not the thing compiles but I'm getting "TypeError: Cannot read property 'format' of undefined" when running the app.

    Original

    Ah, stupid me. I just had to inject Moment into the class. Obviously.

    So here's the working version:

    import { Moment } from 'moment';
    import { autoinject } from "aurelia-framework";
    
    export class App {
      message = 'Hello World!';
      moment: Moment;
    
      constructor(moment : Moment){
        this.moment = moment;
      }
    
      hello() : string {
        return this.moment.format();
      }
    }
    

提交回复
热议问题