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>