0

How to call ng-controller method of angular.js after IBM worklight adapter success function?

I am using below function:

$("#viewCont").bind('click', function () {
    var input = {
        adapter: "sampleAdapters",
        procedure: "GetViewList",
        parameters: [empId]
    };
    WL.Client.invokeProcedure(input, {
        onSuccess: function viewinAngular($scope, data) {
            demoArray = ["Dynamic Group Header - 1", "Dynamic Group Body - 1", "Dynamic Group Header - 2", "Dynamic Group Body - 2"];
            qtyArr = [];
            for (var i = 0; i < demoArray.length; i++) {
                var dataObject = new Object();
                dataObject.dateLocalForamt = '123456';
                dataObject.statusString = 'canclelled';
                dataObject.reqstNumbaa = '123456789';
                dataObject.Product_Desc = 'asdf';
                dataObject.Quantity = 10;
                qtyArr.push(dataObject);
            }

            $scope.data = qtyArr;

        },
        onFailure: authFailure,
        timeout: 180000
    });
}

function authFailure(response) {

    WL.SimpleDialog.show("Alert", 'Check your network connectivity.', [{
        text: "OK",
        handler: function () {}
    }]);
}
nspeete
  • 659
  • 3
  • 10
praveen
  • 3
  • 1
  • 1
    Have you looked here: http://stackoverflow.com/questions/17204562/angularjs-how-do-you-call-a-controller-method-inside-a-javascript-function-defin – nspeete Mar 03 '14 at 23:11
  • Does your code fail? In what manner? Is there an error? And definitely review @nspeete's suggested answer. – Idan Adar Mar 04 '14 at 04:14
  • @nspeete: I looked into that but if i use $http then i will get the proper answer, for worklight every service needs to be request through adapter call. Once i invoke the procedure ll get the output in callback function Onsuccess, how shall i display that in html using angular js? – praveen Mar 05 '14 at 05:21
  • @nspeete: i am unable to get the result the reason behind is ng-controller function will execute when the js load but here i need to call that function after my adapter success kindly help to resolve asap. – praveen Apr 10 '14 at 06:14

1 Answers1

3

In your onSuccess callback function from your adapter invocation you can do the following:

var scope = angular.element(document.getElementById("exampleDivId")).scope();
scope.$apply(function(){

    contact ={type:"phone",value: itemAFromAdapterResponse}; 
    scope.settings.addContact(contact); //html will update based on ng-controller "setting's" function addContact
    scope.settings.name = itemBFromAdapterResponse; //will update name in html as the response from your adapter invocation

})
nspeete
  • 659
  • 3
  • 10
  • :explicitly we need to call bootstrap before calling the ng-controller function, thank you it got worked – praveen Apr 10 '14 at 10:55