我创建了一个 Ionic、AngularJS、phonegap/cordova 应用程序。
在我的 index.html 中,我有这段纯 JavaScript 代码片段:
<script src="js/analytics/launchMyApp.js"></script>
<script type="text/javascript">
function handleOpenURL(url) {
// This function is triggered by the LaunchMyApp Plugin
setTimeout(function() {
alert("Hey the URL: " + url);
console.log(">>>>>>>>> Take me to the launchMyApp controller: " + url);
// Call controller function here
}, 3000);
}
</script>
handleOpenURL 函数由 launchMyApp 插件触发:
nl.x-services.plugins.launchmyapp
这是我的 Controller :
communicatorApp.controller('LaunchMyAppCtrl', function($scope, $state) {
console.log(">>>>>>>> COOL!!!!");
$scope.launchMyAppHere = function(urlIn) {
console.log(">>>>>>>> GO MAN GO: " + urlIn);
};
});
我的问题是我不知道如何从index.html javascript 调用launchMyAppHere 函数?
最佳答案
试试这个:
angular.element($("#elementID")).scope().launchMyAppHere();
其中 #elementID
是附加 Controller 的元素的 DOM ID。
关于javascript - 从index.html javascript调用angularJS Controller 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25059029/