我如何通过PHP变量角度JS? [英] How do I pass PHP variables to angular js?

查看:139
本文介绍了我如何通过PHP变量角度JS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我在角JS逆向工程。所有内容是回荡在一个PHP脚本(不好的做法,我知道,但我将缓和和角只是想使用它的onBlur事件)。

I have a page where I'm reverse engineering in Angular JS. All the content is being echoed in by a PHP script (bad practice I know, but I'm easing into Angular and just wanted to use it for the onBlur event).

我试图找出如何从PHP传递变量角度。变量(客户电子邮件)是不可编辑的,所以我希望把它放在一个隐藏字段。问题是,NG-模型不绑定到隐藏的投入。我需要另一种解决方案。

I was trying to figure out how to pass a variable from PHP to Angular. The variable (customer email) wasn't editable so I wanted to put it in a hidden field. The issue is that ng-model doesn't bind to hidden inputs. I needed another solution..

推荐答案

我找到了一个很好的解决方案<一href=\"http://angularretentive.blogspot.com/2013/09/passing-your-php-variables-to-angular.html?showComment=1395883898464#c7317872000815324734\"相对=nofollow>这里

I found a great solution here

我最终没有创造我的控制器单独的初始化函数,而只是在一个隐藏的输入的NG-初始参数做了它内联:

I ended up not creating a separate init function in my controller but simply did it inline in the ng-init param of a hidden input:

<td><?php echo $db_unit[$i]['email_id']; ?><input type="hidden" ng-init="customer.email='<?php echo $db_unit[$i]['email_id']; ?>'"></td>

我绊倒的是,你必须把价值customer.email在''我是有没有在这之前的报价和它没有工作。一个显而易见的事情。

One obvious thing I tripped over was that you have to put the value for customer.email in '' I had it without quotes before that and it didn't work.

这篇关于我如何通过PHP变量角度JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆