gpt4 book ai didi

javascript - 从 index.html javascript 调用 angularJS Controller 函数

转载 作者:行者123 更新时间:2023-11-29 21:58:43 25 4
gpt4 key购买 nike

我创建了一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com