AngularJS GlobalCtrl vs $rootScope vs Service

前端 未结 2 1089
不知归路
不知归路 2021-02-04 04:03

I am confused on a couple of things with Globals in Angular. Below is my pseudo code.

1) With the way I have my GlobalCtrl placed, I am able to reference my $scope.modal

2条回答
  •  伪装坚强ぢ
    2021-02-04 04:30

    Generally speaking global variables are considered bad practice, as they don't encourage encapsulation, make debugging difficult, and promote bloated code. Here's a good discussion of global variables: http://c2.com/cgi/wiki?GlobalVariablesAreBad.

    A good rule of thumb is to add properties and methods to the most local scope possible and use services to share data between modules.

提交回复
热议问题