Working with $scope.$emit and $scope.$on

前端 未结 12 1261
花落未央
花落未央 2020-11-21 15:22

How can I send my $scope object from one controller to another using .$emit and .$on methods?

function firstCtrl($scop         


        
12条回答
  •  青春惊慌失措
    2020-11-21 15:31

    According to the angularjs event docs the receiving end should be containing arguments with a structure like

    @params

    -- {Object} event being the event object containing info on the event

    -- {Object} args that are passed by the callee (Note that this can only be one so better to send in a dictionary object always)

    $scope.$on('fooEvent', function (event, args) { console.log(args) }); From your code

    Also if you are trying to get a shared piece of information to be available accross different controllers there is an another way to achieve that and that is angular services.Since the services are singletons information can be stored and fetched across controllers.Simply create getter and setter functions in that service, expose these functions, make global variables in the service and use them to store the info

提交回复
热议问题