angular-activerecord icon indicating copy to clipboard operation
angular-activerecord copied to clipboard

Any example how to use it with ES6?

Open mchapliuk opened this issue 9 years ago • 3 comments

Is there a way to use angular-activerecord with es6? BaseModel -> ChildModel ?

mchapliuk avatar Apr 14 '16 10:04 mchapliuk

class ChildModel extends ActiveRecord

bfanger avatar Apr 23 '16 13:04 bfanger

I'm having some problems with this. I would like to use Active Record in a service.

My code is the following:

import ActiveRecord from 'angular-activerecord';


class ExampleService extends ActiveRecord {

    static factory(){
        ExampleService.instance = new ExampleService();
        return ExampleService.instance;
    }

    constructor() {
        super();
    }


ExampleService.factory.$inject = [];

export default ExampleService;

I get the following error : Error: (SystemJS) TypeError: Super expression must either be null or a function, not object(…)

A console.log(ActiveRecord); returns Object {}.

Could you provide an example how to correctly do this?

Thank you very much!

isonet avatar Jul 11 '16 13:07 isonet

@isonet import ActiveRecord from 'angular-activerecord'; won't return the ActiveRecord constructor function. I've made an attempt to convert to an UMD module so I could return the ActiveRecord constructor, but was unsuccessful because it conflicts with the angular 1 module system. And switching to using ActiveRecord.$inject would change the constructor signature.

ES6 Usage:

import 'angular-activerecord';

angular.module('my-module').factory('ExampleService', ['ActiveRecord', function (ActiveRecord) {

    class ExampleService extends ActiveRecord {

        constructor(properties, options) {
            super(properties, options);
        }
    }

    ExampleService.instance = new ExampleService();

    return ExampleService 
}]);

bfanger avatar Jul 26 '16 10:07 bfanger