drzfnr0275 2015-05-18 18:47
浏览 63

使用PHP调用AngularJS函数

I have an angular app which need to load a php page in view. Everything works great. But I need to run an angular function after the php code loads.

How can I call an angular function from php. This is the function I need to call.

$emit('iso-method', {name:null, params:null})

I could write call a javascript function but I'm unsure how to call an angular function with that either.

echo '<script type="text/javascript">'
   , 'myfunction();'
   , '</script>'
;
  • 写回答

1条回答 默认 最新

  • dsy19811981 2015-05-18 19:53
    关注

    You can not call an angular function from PHP. But you could call an angular function from javascript or jquery. I was stuck with same problem in one of my project, what I did See below examples.

    Call angular function from javascript: Your controller element like

    <div id="demoElement" ng-app='MyModule' ng-controller="MyController">
    </div>
    

    and in your script

    <script>
        window.onload = function () {
            angular.element(document.getElementById('demoElement')).scope().emit('name','params');
        }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题