我在响应中调用脚本 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/