我承认我是 AngularJS 的新手,但仍然不太了解它。 但是,我的问题是我需要从 Controller 调用外部 .js 文件中的函数。
这是我的代码:
menuapp.controller("barcodeController", function($scope, $cordovaBarcodeScanner) {
$scope.scanBarcode = function() {
$cordovaBarcodeScanner.scan().then(function(imageData) {
var code = 36;//imageData.text.split('=')[1];
if(code) {
//external function
}
console.log("Barcode Format -> " + imageData.format);
console.log("Cancelled -> " + imageData.cancelled);
}, function(error) {
console.log("An error happened -> " + error);
});
};
});
我用它来扫描条形码,提取“=”后面的内容并将其发送到外部函数。但是我不能简单地调用这些函数,而且我也想不出一种简单的方法来做到这一点。
有什么帮助吗?
最佳答案
如果您从 html 引用外部 Javascript 文件,您将可以从 Controller 内访问该函数。
HTML:
<script src="URL"></script>
Controller :
if(code) {
openrestaurant(code);
}
关于javascript - 从 AngularJS 调用外部函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32750004/