angularjs - 我们如何在 Angular JS 中获取运行时的脚本响应方法

标签 angularjs

我在响应中调用脚本 URL 我需要使用包含方法的响应。我需要在我的代码中实现该方法。请建议是否有人有解决方案

我有下面的 URL,我在指令中调用脚本 URL

script URL = https://botsrv.com/qb/widget/xxxxx/xxxxx

这是我的指令-

directive('demo',[ function () {
    return {
        restrict: 'A',
        link: function(scope, el , attrs) 

            var scriptElem = angular.element(document.createElement('script'));
            scriptElem.attr("src", 'https://botsrv.com/qb/widget/xxxxxx/xxxxx'); // set var appropriately
            el.append(scriptElem);

        }
    };
}])

具有onSave方法的脚本 这是方法 - 我需要 JS Controller 中的 onSave 函数的结果。

onSave: function (results) {
    console.log('onSave method ---- ' , results);
 }

最佳答案

如果你想使用这个函数的响应

onSave: function (results) {
    console.log('onSave method ---- ' , results);
}

因此您必须使用变量或 $scope 来捕获此函数的结果。

ScriptApp.controller('scriptController', function($scope, demo){
    $scope.result = [];
    $scope.getListUsers = function(){
        demo.OnSave().then(function(response){
            $scope.result = response.data.result;
        });
    }
});

通过上面的方法可以得到controller中函数的响应。

关于angularjs - 我们如何在 Angular JS 中获取运行时的脚本响应方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59657257/

相关文章:

javascript - AngularJS 指令中的两个绑定(bind)

javascript - $location 不会在第一次 ng-click 回调时导航

javascript - 使用 sanitize 将 angularjs 字符串变量转换为 html 元素

javascript - 在 OpenCPU 中使用 AngularJS $scope

javascript - 在 AngularJS 中提交表单?

AngularJS Jasmine 测试 get-request

javascript - 通过 Web 凭证 API 通过 JavaScript 对象存储凭证?

javascript - 用于发送 Twilio SMS 消息的 AngularJS 服务

javascript - 使用值作为值语法时,AngularJS select 不绑定(bind)

angularjs - 自定义 ng-options 选择外观