Athit Upakan Athit Upakan - 1 year ago 84
AngularJS Question

How use 2 controllers in one input

Need get data from ControllerB and use selected in ControllerA

<select class="form-control selectpicker" title="All" selectpicker
ng-options="item as item.DISPLAY for item in ControllerB.ComboStatusListResult">


Answer Source

I think the best possible solution is to use data transfer services in angular js to get the ComboStatusListResult in ControllerB to ControllerA and there after using the options from ControllerA itself.

Sample data transfer service.

myApp.factory('DataTransfer', function () {

    var data = {
        Options: ''

    return {
        getOptions: function () {
            return data.Options;
        setOptions: function (Options) {
            data.Options= Options;

and from ControllerB set the ComboStatusListResult object to the service.

myApp.controller('ControllerB', function ($scope, DataTransfer) {



and in ControllerA receive the options to its scope object

myApp.controller('ControllerA', function ($scope, DataTransfer) {

    $cope.ComboStatusListResult = DataTransfer.getOptions();


and in your template use it as.

<select class="form-control selectpicker" title="All" selectpicker
        ng-options="item as item.DISPLAY for item in ComboStatusListResult"></select>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download