- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 StackOverflow 上遇到与许多人相同的问题后,我无法理解什么是“外部 Angular 区域”服务?
我已经检查了围绕这个主题的所有现有问题,这正是我需要问这个问题的原因:
this.myService.method().subscribe(e => {
this.value = e;
});
最佳答案
你想要的代码是NgZone.isInAngularZone()
.这会告诉你它是否在那里执行。
资料来源:在写这篇文章之前,我花了好几个小时阅读 Angular 文档。
此外,您可以注入(inject) NgZone
进入您的服务并尝试使用this.ngZone.run(() => yourSubscriberCallback())
这应该会有所帮助,尽管我尝试这个的结果很复杂。
编辑:好的,我设法让我的东西正常工作,让我们看看它是否对你有帮助。
在我的例子中,我使用了一个第三方库,其中包括一个监听器来进行更改。我使用的是 RXJS BehaviorSubject
通过服务将这些更改传播到各个组件,但这些更改没有被拾取。
原来这是因为我在监听器中使用的方法是在 AngularZone 之外执行的。
起初我是这样做的:
export class Service {
public BehaviorSubject<Thing> thingSubject = new BehaviorSubject<Thing>(new Thing());
constructor(private ngZone:NgZone) {
thirdPartyLibrary.listen(ngZone.run(() => myCallback.bind(_this)));
}
...
}
myCallback
正在做:
myCallback(thing) {
this.thingSubject.next(thing);
}
export class Service {
public BehaviorSubject<Thing> thingSubject = new BehaviorSubject<Thing>(new Thing());
constructor(private ngZone:NgZone) {
thirdPartyLibrary.listen(myCallback.bind(_this));
}
myCallback(thing) {
this.ngZone.run(() => this.thingSubject.next(thing));
}
}
关于 Angular 2 : what make a service to be "Outside" angular zone?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44391696/
我有问题如何在 Go 中打印变量 for,in outside for,in outside for?我正在使用库 GJSON gjson 我尝试了很多方法,我只是输入了全局变量但只是出现了最终索引,
loadJSON(path, callback) { console.log("path: " + path); var xobj = new XMLHttpRequest();
假设我有一个常规的简单 Java 类,例如: public class Foo { private int data; public int getData() { r
如何仅在可能跨越多行的任意长度的文本上实现外边框,必须是响应式的。 寻找类似于下图的样式。 这是我迄今为止尝试过的方法,在顶部边框和对屏幕尺寸的响应能力以及使用各种字体大小(我所拥有的最好的字体大小)
我有一个文本,它是一个 html 文本,我不知道里面有什么(实际上它就像一个文本博客)。 我想做的是用一个带有适当 CSS 的 div 将它括起来,这样我可以确定这个文本中的任何内容(尤其是太大的图片
我正在尝试运行一个并行循环(免责声明:我是并行处理的新手,这可能是一个非常愚蠢的问题)。本质上,我希望能够在并行函数中启动和终止循环,并且能够不时地检查其状态。 我尝试编写一个非常基本的示例(见下文)
我得到了一系列非负整数。 43 18 5 67 1 72 16 17 15 93 38 6 83 10 49 98 7 47 61 52 71 79 82 52 8 我需要将它存储在 Outside-
我有问题。 我想在每个带有“.shadowed”类的图像下添加一个 shadow.jpg 图像。 所以: .shadowed { border: solid 1px #fff; mar
我写了这个CSS: div { width: 500px; height:150px; margin-left:150px; background: lightblue; } div:
我有一种情况,我需要根据对象的日期来验证嵌套对象的日期范围。 因此,假设我有一个名为: Course{ Date date Teacher teacher } Teacher{ Date effect
在 JavaScript 中,我有一个对象数组和一个输入值,如下所示: const inputVal = 'foo'; const objArray = [ {title: 'blahaa',
我想可视化实时传感器数据(流数据)。为此我使用了 node.js、html 和 mysql。 Mysql用于存储实时传感器数据,index.html实现google chart doPoll app.
我有以下代码。有两个枚举。一个有 16 个值 (A_) 和另一个有 15 个值 (A1_)。 #include typedef enum { A_0 = 0, A_1,
我假设这样写对吗 auto && x = ...; 在 for 范围的 for (...) 部分之外几乎没有任何意义,因为如果右侧确实是右值,它通常会停止存在于分号和然后 x 指的是已经被破坏的东西。
list-style-position 时是否无法调整背景图像?是outside ? 示例: li {list-style:decimal;background:url(images/bg-li.pn
我刚刚开始尝试使用 css 中的 shape-outside 属性,但无论我浏览了多少文档或博客,我都无法使其正常工作。我可能犯了一个愚蠢的错误,但我不确定。谁能指出错误? #q { backgr
我是 css 网格的新手 我尝试从附加的图像中实现布局,其中 ONE 元素 DIV 4 比网格布局宽。我尽量避免在 DIV 4 之前关闭 grid-div,然后在 DIV 4 之后再次重新打开网格,这
查看此 code-pen : * { min-height: 100% } #image-sculptor { display: block; height: 321px; width
我想更改字体并加粗 div.main2 之外的元素, 但将元素保留在 div.main2 中不受影响。 我尝试使用 :not(.main2)和 strong *:not(.main2)但逻辑似乎不对
我有一个小设计问题,我似乎无法理解。也许我可以在这里找到一些有创造力的人,他们可以为我指明方向——我相信我现在有创造力障碍:( 在我解释之前,请看下面的例子。这让事情变得更容易: http://jsf
我是一名优秀的程序员,十分优秀!