Integrating native JavaScript classes in an Angular app

后端 未结 2 527
借酒劲吻你
借酒劲吻你 2021-01-16 08:50

I have a native JavaScript class:

var Holder = new function(elements) {

    this.elements = elements;

    this.any         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 09:41

    You could return a class with a factory

        .factory('Holder', function() {
            return (function (){
                this.foo = foo;
                this.bar = bar;
            });
        });
    

    Now to use it

    .controller('AnyController', ['Holder', function (Holder) {
        var holder = new Holder();
    }]);
    

    EDIT Use a factory instead of a service, as suggested in the comments

提交回复
热议问题