What's the correct way to communicate between controllers in AngularJS?

前端 未结 19 2418
猫巷女王i
猫巷女王i 2020-11-21 22:02

What\'s the correct way to communicate between controllers?

I\'m currently using a horrible fudge involving window:

function StockSubgro         


        
19条回答
  •  囚心锁ツ
    2020-11-21 23:04

    Regarding the original code - it appears you want to share data between scopes. To share either Data or State between $scope the docs suggest using a service:

    • To run stateless or stateful code shared across controllers — Use angular services instead.
    • To instantiate or manage the life-cycle of other components (for example, to create service instances).

    Ref: Angular Docs link here

提交回复
热议问题