我正在使用Angular 7并面临一个问题=>登录后,API GET调用成功,组件也接收数据,但UI没有显示该数据.
当我打开浏览器控制台时,会立即在UI上填充数据并在控制台中显示警告.
"core.js:15686在Angular区域外触发导航,您是否忘记调用'ngZone.run()'?"
我已经搜索了这个警告并找到了一些解决方法,并在其中this.ngZone.run()调用我的API.
但问题是,我使用了40多个组件,并在每个组件中调用了这么多API.所以我必须调用ngZone.run()每个API调用,这似乎很难做到.
请建议我更好的方法来克服这个问题.提前致谢.
app.component.ts
getEmployees(): void {
this.employeeService.getEmployees().subscribe(e => {
this.employees = e;
});
}
Run Code Online (Sandbox Code Playgroud)
app.service.ts
@Injectable()
export class EmployeeService {
constructor(private httpClient: HttpClient) { }
getEmployees() {
return this.httpClient.get<EmployeeModel[]>('employees');
}
Run Code Online (Sandbox Code Playgroud) 我正试图理解这个ChangeDetectionStrategy.OnPush机制.
我从读数中得到的结论是,通过比较旧值和新值来进行变化检测.如果对象引用未更改,则该比较将返回false.
然而,似乎某些情况下绕过了"规则".你能解释一下这一切是如何运作的吗?
这是一个糟糕的星期四.这是第13次.昨天我向我的同事们解释了我们对星期四的第13次下降有多么幸运,而不是周五.
好吧,那是昨天,今天我醒来时脸上有棱角的拳头:
无法在字符串'__zone_symbol__optimizedZoneEventTask'上创建属性' creationTrace '
那么它也可能是zone.js,或者甚至更深层次的暗深深处叫做开发堆栈.有谁能够帮我?
对不起我的态度,只是因为早期的alpha阶段工作角度最终对我造成了影响.
PS:我只想说,自昨天工作版以来我没有改变任何东西.因此,我完全迷失了为什么以及如何以及在何处以及在何处发现此错误...
我已经从RC4升级到Angular2的最终版本.当我运行时npm start,应用程序停留在"正在加载...",我得到的唯一错误是关于Zone.js:
基本上,typeof Zone未定义:
这是我的package.json:
"engines": {
"node": ">= 4.2.1",
"npm": "3.10.7"
},
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/platform-server": "2.0.0",
"@angular/router": "3.0.0",
"@salesforce-ux/design-system": "^2.0.3",
"angular2-busy": "^0.3.2-rc.6",
"chart.js": "2.1.0",
"core-js": "^2.4.0",
"d3": "^4.2.3",
"lodash": "^4.14.0",
"moment": "^2.14.1",
"ng2-bootstrap": "^1.1.4",
"ng2-charts": "^1.1.0",
"ng2-datepicker": "^1.0.6",
"ng2-pagination": "^0.4.1",
"normalize.css": "^4.1.1",
"rxjs": "5.0.0-beta.12",
"typescript": "2.1.0-dev.20160916",
"zone.js": "0.6.21"
},
"devDependencies": {
"@angular/compiler-cli": "^0.6.1",
"@types/core-js": "^0.9.28",
"@types/hammerjs": "^2.0.28",
"@types/jasmine": "^2.2.29",
"@types/lodash": "^4.14.34", …Run Code Online (Sandbox Code Playgroud) 从 Angular 9 升级到 10 后,我在运行 ng serve 时收到这些警告:
WARNING: Zone.js does not support native async/await in ES2017.
These blocks are not intercepted by zone.js and will not triggering change detection.
See: https://github.com/angular/zone.js/pull/1140 for more information.
(node:56581) ExperimentalWarning: The fs.promises API is experimental
Run Code Online (Sandbox Code Playgroud)
有人知道这意味着什么,如果这是我应该关心的事情吗?
我使用了一个Angular 4项目@angular/cli,在开发模式下运行应用程序时,我在控制台中收到了这些警告:
zone.js:1489 [Violation] 'setTimeout' handler took 209ms
2[Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive.
zone.js:1157 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive.
zone.js:1157 [Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive.
2zone.js:1157 [Violation] …Run Code Online (Sandbox Code Playgroud) 我收到错误消息:
未处理的Promise拒绝:Zone.assertZonePatched不是函数
虽然我在index.html中正确导入zonejs:
<script src="https://unpkg.com/zone.js@0.6.17/dist/zone.js"></script>
Run Code Online (Sandbox Code Playgroud)
这是代码:
Plnkr:http://plnkr.co/edit/zZYOcgxcRINx23JhuxOk?p =preview
这有什么不对?
我有一个中等大小的Angular应用程序,由于某些原因,我的一些量角器测试在我的实时生产环境中运行时超时.
我很确定超时发生是因为量角器等待某个异步任务.我知道区域,我试图将所有长时间运行的异步任务保留在ngZone之外(根据常见问题解答),但由于某些原因,量角器仍然超时.
我可能错过了一些东西,但我不知道如何调试问题.有没有办法找出代码量角器的哪一部分正在等待?
NgZone只公开函数来确定是否有微任务或macrotasks运行,但不告诉我哪一个.
编辑:量角器显示的这种超时错误的典型示例:
失败:超时等待异步Angular任务在11秒后完成.这可能是因为当前页面不是Angular应用程序.有关详细信息,请参阅常见问题解答:https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
在等待带定位器的元素时 - 定位器:By(css选择器,[data-e2e ='scroll-to-offer'])
该元素存在于页面上(我已经手动验证过),但量角器仍然超时.
问题如下:根据定义,当前时间每个时刻都在不断变化.但Angular 4变化检测系统无法检测到它.出于这个原因,在我看来,有必要明确地打电话ChangeDetectorRef::detectChanges.但是,在调用此方法的过程中,当前时间自然会改变其值.这导致了ExpressionChangedAfterItHasBeenCheckedError.在以下示例中(请参阅实时),加载页面后几秒钟会出现此错误:
import { Component, ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'my-app',
template: `{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />
{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />
{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />{{ now }}<br />
{{ now }}<br …Run Code Online (Sandbox Code Playgroud) 在Chrome中,一切正常,但在Firefox中,绑定永远不会更新.
这个问题似乎core-js和/或有关zone.js:
这些问题是固定的,但我是最新版本的angular(v2.4.9),它不起作用.
我导入polyfill.ts,这是:
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
Run Code Online (Sandbox Code Playgroud)
在main.ts.我尝试在zone.js导入之前按照core-js其中一个Github门票建议导入,但它不起作用.
我需要包含或链接的另一个polyfill index.html吗?
看起来它在Firefox中的实际工作时间占50%.如果我刷新页面,它将每隔一段时间正确呈现页面.当它不起作用时,绝对没有绑定工作; 不执行事件回调,{{ ... }}不呈现绑定等.
这个错误实际上是由我在index.html中链接的Polymer的platform.js(Polymer的 polyfills)引起的.如果我将其删除,绑定将再次开始工作.我在我的应用程序中实现了这个Midi合成器,它使用了Polymer,这需要platform.js.所以似乎Firefoxplatform.js和Angular2 之间存在冲突.有没有办法解决这个冲突?
angular ×10
zonejs ×10
javascript ×3
polyfills ×2
firefox ×1
protractor ×1
rxjs ×1
typescript ×1