角度视图模型和来自dom的数据 [英] Angular viewmodels and data from the dom

查看:129
本文介绍了角度视图模型和来自dom的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将新的角度功能集成到旧应用程序中。旧应用程序中的模式是服务器加载数据并将其作为请求的一部分呈现给dom的模式。这与Angular提供的模式相反,服务器呈现最小的轻量级页面,然后通常使用角度服务通过ajax调用加载数据。



我不想过多地混合模式并在我们的解决方案中造成混乱,而且有些情况下我们的服务器已经因其他原因而必须完成这项工作,并且利用我们拥有的事实是有意义的数据,而不是做一些完全不需要的额外的ajax调用。



作为一个黑客和权宜之计,我偶尔会让服务器将一个json对象渲染成一个javascript全局变量和完成$ scope.data = _my_ugly_global_variable; //在这里哭泣和哭泣。



我有一些想法可以更好地处理这个问题,但我并不总是对他们感到高兴。



此外,它引出了一个不同的问题。如果我想拥有给定角度视图的两个实例,但我希望它们每个都有独立的数据,那么最好的方法是什么?如何通知控制器功能一个实例应该获取dataA而实例二应该获取dataB?



再次,我有一些想法,我可以继续工作,但我如果有一些人们可以分享的优雅解决方案,我真的不想重新发明这个问题。



谢谢,



Danny

解决方案

< blockquote> scope.data = _my_ugly_global_variable; //在这里哭泣和哭泣。



我有一些想法可以更好地处理这个问题,但我并不总是满意他们。



此外,它引出了一个不同的问题。如果我想拥有给定角度视图的两个实例,但我希望它们每个都有独立的数据,那么最好的方法是什么?如何通知控制器功能一个实例应该获取dataA而实例二应该获取dataB?



再次,我有一些想法,我可以继续工作,但我如果有一些人们可以分享的优雅解决方案,我真的不想重新发明这个问题。



谢谢,



Danny


I am integrating new angular functionality into an older application. The pattern in the older application is one where the server loads data and renders it to the dom as part of the request. This is kind of opposite to the pattern that Angular lends towards, where the server renders a minimal, light page and then the data is typically loaded via an ajax call using an angular service.

I don''t want to mix patterns too much and create that confusion in our solution, plus there are cases where our server already has to do the work for other reasons and it makes sense to leverage the fact that we have the data rather than do some additional ajax calls that are completely unneeded.

As a hack and stopgap, I have occasionally had the server render a json object into a javascript global variable and done $scope.data= _my_ugly_global_variable;//tears and crying here.

I have some ideas for better ways to handle the issue, but I am not always happy with them.

Furthermore, it leads me to a different question. If I want to have two instances of a given angular view, but I want them to each have independent data, what''s the best way to do that? How do I inform the controller function that one instance should get dataA while instance two should get dataB?

Again, I have some ideas that I could work on, but I don''t really want to reinvent the wheel on this if there are some elegant solutions that people can share.

thanks,

Danny

解决方案

scope.data= _my_ugly_global_variable;//tears and crying here.

I have some ideas for better ways to handle the issue, but I am not always happy with them.

Furthermore, it leads me to a different question. If I want to have two instances of a given angular view, but I want them to each have independent data, what''s the best way to do that? How do I inform the controller function that one instance should get dataA while instance two should get dataB?

Again, I have some ideas that I could work on, but I don''t really want to reinvent the wheel on this if there are some elegant solutions that people can share.

thanks,

Danny


这篇关于角度视图模型和来自dom的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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