【问题标题】:Call angularJS controller function from index.html javascript从 index.html javascript 调用 angularJS 控制器函数
【发布时间】:2014-07-31 12:36:03
【问题描述】:

我创建了一个 Ionic、AngularJS、phonegap/cordova 应用程序。

在我的 index.html 中,我有这个纯 javascript 的 sn-p:

  <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>

从launchMyApp插件触发handleOpenURL函数:

  nl.x-services.plugins.launchmyapp

这是我的控制器:

  communicatorApp.controller('LaunchMyAppCtrl', function($scope, $state) {

     console.log(">>>>>>>> COOL!!!!");

     $scope.launchMyAppHere = function(urlIn) {
         console.log(">>>>>>>> GO MAN GO: " + urlIn);
     };

  });

我的问题是我不知道如何从 index.html javascript 调用 launchMyAppHere 函数?

【问题讨论】:

  • 这还不是很清楚。如果您需要帮助,这个问题需要认真检查。
  • 查看我接受的答案 - 有人理解我 ;)

标签: javascript angularjs cordova phonegap-plugins


【解决方案1】:

试试这个:

angular.element($("#elementID")).scope().launchMyAppHere();

#elementID 是您附加控制器的元素的 DOM ID。

【讨论】:

  • 谢谢你,我会试试这个:)
  • @lulu88 你能分享 index.html 中对你有用的代码吗?
猜你喜欢
  • 1970-01-01
  • 2014-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-04
  • 2021-04-06
  • 1970-01-01
相关资源
最近更新 更多