angularjs – Angular ng-init:’通过服务器端脚本注入数据’

前端之家收集整理的这篇文章主要介绍了angularjs – Angular ng-init:’通过服务器端脚本注入数据’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
来自关于ng-init的Angular文档:

This directive can be abused to add unnecessary amounts of logic into
your templates. There are only a few appropriate uses of ngInit,such
as for aliasing special properties of ngRepeat,as seen in the demo
below; and for injecting data via server side scripting.

任何人都可以解释第二个用例:

…and for injecting data via server side scripting.

具体来说,使用此指令将值从Rails / PHP视图传递给Angular控制器是否合适?

其他方法(使用$location)似乎不必要地复杂化.

解决方法

绝对.如果您的PHP或Rails应用程序生成模板,并且方便(且安全)将数据从该应用程序作为ng-init属性值传递给Angular应用程序,那么这是一个有效的用例.

如果数据是复杂对象和/或可能更改(或由客户端应用程序更改),则生成$http请求更有用.

猜你在找的Angularjs相关文章