简体   繁体   English

如何强制 angular 手动重新运行其绑定?

[英]How can i force angular to re-run its bindings, manually?

I am trying to integrate angular into an older existing web-app.我正在尝试将 angular 集成到旧的现有网络应用程序中。 I have a few places where large portions of the page are re-rendered from rails partials via ajax requests.我有几个地方通过ajax请求从rails部分重新呈现页面的大部分。

Once a portion of the page is re-rendered in this way, any existing angular bindings (eg: ng-click) are lost and buttons no longer work.一旦页面的一部分以这种方式重新呈现,任何现有的角度绑定(例如:ng-click)都会丢失,按钮不再起作用。 Is there any way to manually tell angular to re-check for binding attributes?有没有办法手动告诉 angular 重新检查绑定属性?

If you are loading some HTML and need angular to process it you'll need to run $compile on the HTML code for angular to parse for directives and you'll need to attach a scope to the returned link function.如果您正在加载一些 HTML 并需要 angular 来处理它,您需要在 HTML 代码上运行 $compile 以便 angular 解析指令,并且您需要将范围附加到返回的链接函数。 Show some code.显示一些代码。 If you are simply getting new data you can use $http which will automatically call $digest for you or else you can call $digest from some other callback to notify angular it needs to update the display.如果你只是简单地获取新数据,你可以使用 $http ,它会自动为你调用 $digest 或者你可以从其他回调中调用 $digest 来通知 angular 它需要更新显示。

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

相关问题 在路由器导航后,如何强制ngFor重新运行? (角度2) - How do you force ngFor to re-run after router navigation? (Angular 2) 如何重新运行Vue.js ApolloClient中间件? - How can I re-run Vue.js ApolloClient middleware? 如何在点击事件上使用 Javascript 在 HTML Div 内重新运行 Django For 循环 - How can I re-run a Django For Loop inside a HTML Div using Javascript on Click Event 我保存时测试失败(在测试脚本配置中使用`--watch`)但如果我手动重新运行它们会通过? - Tests fail when I save (using `--watch` in test script config) but if I re-run manually they pass? 如何重新运行JavaScript代码 - How to re-run javascript code 如何重新运行/重新加载控制器的一部分? - How to re-run/reload a section of a controller? 如何重新运行当前$ state的控制器? - How to re-run the controller of the current $state? 使用来自自身响应的数据重新运行 Ajax - Re-run Ajax with data from its own response 如何强制knockout从其绑定更新模型? - how do I force knockout to update the model from its bindings? 如何重新运行Meteor发布以刷新客户端上集合的内容? - How do I re-run my Meteor publication to refresh the contents of a collection on the client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM