Tabset $rootScope scope not updating

前端 未结 1 1152
无人共我
无人共我 2021-01-21 21:06

I\'ve a screen in below structure.

UserExperienceScreen
       
       tab 1 -  
- input fields - form submit - go to
1条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 21:43

    It is not advisable to pollute the $rootScope like this, instead you can either share a common servce data across your controllers or simply use one controller for all your tabs, such as the following:

    [1] Share a common service data across your controllers:

    DEMO

    JAVASCRIPT

    angular.module('plunker', ['ui.bootstrap'])
    
    .service('Common', function() {
      this.tabData = {};
    })
    
    .controller('SampleController', function($scope, Common) {
      $scope.tabData = Common.tabData;
    })
    
    .controller("SampleTab2Controller", function($scope, Common) {
      $scope.tabData = Common.tabData;
    });
    

    HTML

    
    
       
        

    Text from Tab1

    [2] Use one controller for all your tabs

    DEMO

    JAVASCRIPT

    angular.module('plunker', ['ui.bootstrap'])
    
    .controller('TabController', function($scope) {
    
    });
    

    HTML

      
    
       
        

    Text from Tab1

    0 讨论(0)
提交回复
热议问题