简体   繁体   English

ng-init或等效视图加载

[英]ng-init or equivalent on partial view load

I'm calling a partial view from my angular controller with a GET from the server. 我正在使用服务器的GET从我的角度控制器调用局部视图。 I'm calling $compile on this partial because I'm binding some data to it. 我在此部分上调用$compile是因为我正在将一些数据绑定到该部分。 However, I need one of my scope variables (an object) to get some data from the server once the partial is loaded. 但是,部分加载后,我需要一个作用域变量(一个对象)从服务器获取一些数据。

I tried to add an ng-init='getDataForObject() but this doesnt seem to be working. 我试图添加ng-init='getDataForObject()但这似乎不起作用。 Is there an alternative way of doing this? 有替代的方法吗? or is there a way to call a function once the partial view is loaded. 或在部分视图加载后是否有调用函数的方法。

correct me if I'm wrong, but it looks like this partial view is getting its own instance of the controller, is this true? 如果我错了,请纠正我,但是看起来这个局部视图正在获取其自己的控制器实例,这是真的吗? because I tried to get the object data from inside the GET on the inital call to get the partial, but that didnt work, which must mean that the object isnt the same one as in the partial 因为我尝试从inital调用的GET内部获取对象数据以获取部分数据,但这没有用,这必须意味着该对象与Partial中的对象不同

Have you tried using a general view object and then assigning a sub object. 您是否尝试过使用常规视图对象然后分配子对象。 to handle the subview you are referring to? 处理您所指的子视图? Single level object changes don't propagate to parent scopes in most cases, but multi-level object changes do propagate upward. 在大多数情况下,单级对象更改不会传播到父范围,但多级对象更改确实会向上传播。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM