Using the same controller on different elements to refer to the same object

后端 未结 2 741
慢半拍i
慢半拍i 2020-12-01 01:41

I figured if I slapped ng-controller=\"GeneralInfoCtrl\" on multiple elements in my DOM they would share the same $scope (or least two-way binding

2条回答
  •  时光取名叫无心
    2020-12-01 02:42

    Simply put shared data in the root scope, you'll be able to use them everywhere. In Angular $rootScope is the root of all scopes and can be used in controllers to manage data that must be visible across all modules. To use it just inject it in the controller function. For a detailed explanation refer to the Angular developer's guide and to the API doc.

提交回复
热议问题