- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 Angular 6.0.8 中有一个组件,它只包含一个 iframe。
page.component.html:
<iframe [src]="url">
页面.component.ts:
ngOnInit() {
this.url = this.route.snapshot.data['url];
}
现在,当我调整窗口大小时或在组件外部单击鼠标(失去焦点)时,angular 将重新渲染它(生命周期 Hook 显示:DoCheck、AfterContentChecked、AfterViewChecked)
浏览器会再次请求 iframe 中的 url,这不是我应该做的。
如何防止这种行为?
最佳答案
最推荐的方法之一(不是解决这个具体问题,而是解决所有不需要的重新渲染)是在推送时使用更改检测策略 (ChangeDetectionStrategy.OnPush
)。
A comprehensive guide to angular onpush change detection strategy
By default Angular uses the
ChangeDetectionStrategy.Default
change detection strategy.The default strategy doesn’t assume anything about the application, therefore every time something changes in our application, as a result of various user events, timers, XHR, promises, etc., a change detection will run on all components.
This means anything from a click event to data received from an ajax call causes the change detection to be triggered.
...
OnPush Change Detection Strategy
We can set the ChangeDetectionStrategy of our component to ChangeDetectionStrategy.OnPush .
示例:
@Component({
selector: 'tooltip',
template: `
<h1>{{config.position}}</h1>
{{runChangeDetection}}
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
关于javascript - 当窗口调整大小时或在 Angular 6 中失去焦点时如何防止重新渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53334389/
我在我的项目(Ubuntu 18.04.2 LTS)中使用了 celery 4.4.0 版本。当我提出异常('功能中的功能太少无法分类')时, celery 项目失去了 worker ,我得到了这样的
我在这样的更新面板中有一个 GridView :
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 这个问题似乎不是关于 a specific programming problem,
当我尝试使用 jquery 的 html() 将 HTML 附加到另一个元素时。我失去了 ng-click 的能力。这是我的代码的粗略描述。例如我有一个名为 testController 的 Cont
我正在将 python 连接到 mySqL 数据库,并从 android 发送两个 Double 值以存储在 Mysql 中,然后我收到此错误 enter code here Exception i
无法理解为什么这个简单的事情没有反应性。看起来我错过了一些 Vue 的基础。 {{connection_status}} export default {
我不明白出了什么问题,在我的设备上应用程序运行良好,但有时在日志中(应用程序用户、 session 、崩溃......通过某些服务跟踪)我看到应用程序崩溃(NullPointerException),
我正在处理一个我有点困惑的问题。问题是假设您是二战期间英国空军的一名将军。您还剩下 100 架飞机来保卫英国。在您执行的每个任务中,每架飞机都有 50% 的几率被德国高射炮击落,因此每次执行任务您都会
我相信我的问题与以下问题非常相似 Spring security 'remember me' cookie not avaiable in first request . 基本上,我有一组用于公司内部
似乎 Bootstrap 下拉按钮在单击后仍保持焦点。 我的用例与此不兼容, 用户应该在单击按钮后按“SPACE”键,为了触发与按钮无关的东西。 问题是按钮保持焦点状态,因此按空格键 激活按钮。 我希
我有一个 MKMapView,其中有很多从解析器 xml 定义的注释引脚;那是我的代码: -(IBAction)LoadAnnotation:(id)sender { RXML element
我有一个 HTML 表格,用户可以在其中输入他的待机开始时间和待机结束时间,该时间计算总时数,并基于此计算获得的补偿时数。这一切都有效。 现在,它所做的是,每当用户输入开始和结束时间时,用户必须将焦点
Windows 系统更新后,Eclipse 不再了解 Android 的任何信息...我如何恢复对 Android 的支持?我尝试重新安装 SDK,但没有成功... 太奇怪了。我注意到项目模板丢失了,
我正在发送 SOAP 请求来更新某些实体。当我创建(而不是更新)几乎相同的东西时,一切正常。我跟踪了客户端和传输的日志记录,最后它给了我一个线索。它看起来像这样: DEBUG:suds.client:
这个问题在这里已经有了答案: TypeError: Cannot read property 'setState' of undefined (3 个答案) How to access the co
我使用 PostgreSQL 和 repmgrd 创建了一个 Docker 镜像,所有这些镜像都是使用 supervisor 启动的。 我现在的问题是,当它启动时,由 supervisor 生成的 r
新的 iOS 开发者为 iPhone 编写第一个委托(delegate)应用程序。 模态调用的父 View Controller 有六个 subview Controller ,它们使用父 View
我目前正在 MVC4 中创建一些用户配置文件编辑表单,并且为了测试,我将 UserId 属性呈现为表单上的只读文本框,如下所示: @Html.LabelFor(model => model.
我是一名优秀的程序员,十分优秀!