Angular JS inject new instance of class

前端 未结 3 1293
情歌与酒
情歌与酒 2021-02-20 08:28

I want to inject instances of a class. From this thread it looks like services return new serviceArgFunction, which is what I want. https://groups.google.com/forum/#!msg/angul

3条回答
  •  春和景丽
    2021-02-20 09:02

    To make it clear I created a little Plunker.

    It has a Service and a Factory. Service and Factory have a value and setters and getters.

    Both are injected into Controllers A and B. If You change the value of the Service in Controller A, this change takes also place in Controller B, because the service is a Singleton.

    But when You change the value in the Factory in the Controller B, this affects only B because the change takes only place in the instance that is created in B.

    Enjoy!

提交回复
热议问题