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

前端 未结 19 2445
猫巷女王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:06

    function mySrvc() {
      var callback = function() {
    
      }
      return {
        onSaveClick: function(fn) {
          callback = fn;
        },
        fireSaveClick: function(data) {
          callback(data);
        }
      }
    }
    
    function controllerA($scope, mySrvc) {
      mySrvc.onSaveClick(function(data) {
        console.log(data)
      })
    }
    
    function controllerB($scope, mySrvc) {
      mySrvc.fireSaveClick(data);
    }
    

提交回复
热议问题