【问题标题】:IBM Worklight 6.1 - How to call `ng-controller` method of angular.js after a successful adapter invocation?IBM Worklight 6.1 - 成功调用适配器后如何调用 angular.js 的“ng-controller”方法?
【发布时间】:2014-03-03 13:06:19
【问题描述】:

IBM worklight适配器成功函数后如何调用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 () {}
    }]);
}

【问题讨论】:

  • 你的代码失败了吗?以什么方式?有错误吗?并且一定要查看@nspeete 的建议答案。
  • @nspeete:我对此进行了调查,但如果我使用 $http,那么我将得到正确的答案,因为工作灯需要通过适配器调用来请求每个服务。一旦我调用该过程将在回调函数 Onsuccess 中获得输出,我将如何使用 Angular js 在 html 中显示它?
  • @nspeete:我无法得到结果背后的原因是 ng-controller 函数将在 js 加载时执行,但在这里我需要在适配器成功后调用该函数,请尽快帮助解决。

标签: angularjs jquery-mobile ibm-mobilefirst angularjs-scope worklight-adapters


【解决方案1】:

在适配器调用的 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

})

【讨论】:

  • : 很明显我们需要在调用 ng-controller 函数之前调用 bootstrap,谢谢它成功了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-12
  • 1970-01-01
  • 2014-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-23
相关资源
最近更新 更多