[英]ng2 initialize DOM property once and drop change detection
In angular 1, I can do 在角度1中,我可以做
<span ng-bind="::expression"></span>
to set the innerHTML of the span without creating a watcher. 设置范围的innerHTML而不创建观察者。
In angular 2, I'm thinking of a few ways to do it but I don't know if the change detector is still alive after initialization. 在角度2中,我正在考虑几种方法,但我不知道初始化后更改检测器是否仍然有效。 Since I just want to initialize the innerHTML once, it would be nice to remove change detection after first pass. 由于我只想初始化一次innerHTML,因此最好在首次通过后删除更改检测。 Can someone help? 有人可以帮忙吗?
<span [innerHTML]="expression"></span>
<span innerHTML="{{expression}}"></span>
<span>{{expression}}</span>
And regarding 2. I found in official document that bracket can be ommitted when doing string initialization, but I don't know what happens when it's combined with {{}} interpolation. 关于2.我在官方文档中发现,在进行字符串初始化时可以省略括号,但是我不知道将其与{{}}插值结合使用会发生什么。 https://angular.io/docs/ts/latest/guide/template-syntax.html#!#one-time-string-initialization https://angular.io/docs/ts/latest/guide/template-syntax.html#!#one-time-string-initialization
You can change the way how a component does change detection : 您可以更改组件更改检测方式的方式:
@Component({changeDetection:ChangeDetectionStrategy.OnPush})
class MyComponent {
...
}
More information: http://blog.thoughtram.io/angular/2016/02/22/angular-2-change-detection-explained.html and http://victorsavkin.com/post/110170125256/change-detection-in-angular-2 更多信息: http : //blog.thoughtram.io/angular/2016/02/22/angular-2-change-detection-explained.html和http://victorsavkin.com/post/110170125256/change-detection-in -angular-2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.