AngularJS: How can I pass variables between controllers?

后端 未结 16 2581
误落风尘
误落风尘 2020-11-22 00:31

I have two Angular controllers:

function Ctrl1($scope) {
    $scope.prop1 = \"First\";
}

function Ctrl2($scope) {
    $scope.prop2 = \"Second\";
    $scope.         


        
16条回答
  •  盖世英雄少女心
    2020-11-22 01:17

    There are two ways to do this

    1) Use get/set service

    2) $scope.$emit('key', {data: value}); //to set the value

     $rootScope.$on('key', function (event, data) {}); // to get the value
    

提交回复
热议问题