如何将多个参数传递给$ on service

时间:2017-07-07 07:02:59

标签: angularjs

我有两个字段,我想使用$ on service传递给我的控制器。 这是第一个js

$scope.submitFilterForm = function(query){     
    var query='test';
    var deviceType= filterStateService.getActiveFilterState();
    messageBus.send(Message.SubmitFilterForm,query,deviceType);
}

现在我必须将两个变量传递给其他控制器。其他控制器中的查询正确,但设备类型未定义。 我的问题是我们可以传递多个参数。

$scope.$onMessage(Message.SubmitFilterForm,function(event,data,deviceType) {    
    console.log("Value of data n device type is",data);
    console.log("Value of data n device type is",deviceType);
}

1 个答案:

答案 0 :(得分:1)

你可以传递一个对象:

messageBus.send(Message.SubmitFilterForm,{ query: query, deviceType: deviceType});

$scope.$onMessage(Message.SubmitFilterForm,function(event,data) {    
            console.log("Value of data n device type is",data.query);
            console.log("Value of data n device type is",data.deviceType);
            }