V
V
vasIvas2015-09-12 17:49:56
Angular
vasIvas, 2015-09-12 17:49:56

Why is the behavior of a service different from that of the constructor function of that service?

There is a class C which I use as a service. When I get it in the run method and manually create class A, everything works fine, that is, the render result is visible. But if I design class A as a service, then nothing is displayed. In the console, a manually created object and a service object look exactly the same.
what could be the problem? If this is such synchronicity, then why does it only apply to angular objects? And to be honest, this cannot be synchronicity, since I see that the service is created before I add it. What's the matter? I understand that you do not understand what kind of render I have there ... Canvas render .. At least express your thoughts, otherwise I don’t have any at all.

class A {
    constructor(){
        // здесь происходит создание класса B и его рендер
    }
}

class C {
    constructor(){
        
    }
    
    addChild(child){
        this._stage.addChild(child);
    }
}

// и где-то в коде

var a = new A();

stageService.addChild(a); // все прекрасно рендерится

And I remembered something else... It seems that there is a console on the plunker that shows the synchronous operation of the code. Doesn't this happen in phpstorm or chrome? otherwise it may be that the console is lying that the service exists ... But if angular has already injected it, then it means it exists ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-09-13
@vasIvas

Nothing is clear from your question, please provide the code and by what signs do you determine that something is wrong?
According to your task: dependency inversion and factories.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question