呼叫用PHP AngularJS功能 [英] Call a AngularJS function with PHP
问题描述
我有一个角度应用程序,它需要考虑到加载PHP页面。一切都很正常。但我需要的PHP code加载后运行一个角度的功能。
我如何可以调用从PHP的角度的功能。这是我需要调用的函数。
$排放(异法',{名:空,则params:空})
我可以写调用javascript函数,但我不能确定如何可以调用与角度的功能。
回声'<脚本类型=文/ JavaScript的>'
'myfunction的();'
,'< / SCRIPT>'
;
您不能调用从PHP的角度的功能。但你可以从JavaScript调用或jQuery的一个角度的功能。我坚持了同样的问题,在我的项目之一,我确实看到了下面的例子。
从JavaScript调用角功能:
喜欢你的控制器单元
< DIV ID =demoElementNG-应用='MyModule的'NG控制器=myController的>
< / DIV>
在你的脚本
<脚本>
在window.onload =函数(){
。angular.element(的document.getElementById('demoElement'))范围内(中)发射('名','参数');
}
< / SCRIPT>
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>'
;
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>
这篇关于呼叫用PHP AngularJS功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!