Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Any example how to use it with ES6? #24

Open
mchapliuk opened this issue Apr 14, 2016 · 3 comments
Open

Any example how to use it with ES6? #24

mchapliuk opened this issue Apr 14, 2016 · 3 comments

Comments

@mchapliuk
Copy link

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

@bfanger
Copy link
Owner

bfanger commented Apr 23, 2016

class ChildModel extends ActiveRecord

@isonet
Copy link

isonet commented Jul 11, 2016

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!

@bfanger
Copy link
Owner

bfanger commented Jul 26, 2016

@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 
}]);

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

No branches or pull requests

3 participants