0

如何在IBM worklight適配器成功函數後調用ng-controller angular.js的方法?IBM Worklight 6.1 - 在成功的適配器調用後如何調用angular.js的ng-controller方法?

我使用以下功能:

$("#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() {} 
    }]); 
} 
+1

有你看這裏:http://stackoverflow.com/questions/17204562/angularjs-how-do-you-call-a-controller-method-inside-a-javascript-function-defin – nspeete

+0

你的代碼失敗了嗎?以什麼方式?有錯誤嗎?絕對回顧@ nspeete的建議答案。 –

+0

@nspeete:我看了一下,但如果我使用$ http,那麼我將得到正確的答案,對於worklight,每個服務都需要通過適配器調用請求。一旦我調用過程ll獲取回調函數Onsuccess中的輸出,我將如何顯示在HTML中使用角js? – praveen

回答

3

在你的onSuccess回調函數從您的適配器調用,你可以做到以下幾點:

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 

}) 
+0

:明確我們需要在調用ng-controller函數之前調用bootstrap,謝謝它得到了工作 – praveen

相關問題