简体   繁体   English

Angular 2 + JSPM:无法按预期工作

[英]Angular 2 + JSPM: not working as expected

I have Angular 2 (beta.6) installed using JSPM. 我已经使用JSPM安装了Angular 2(beta.6)。 When I then start my app I get the message of 'reflect-metadata' being required (see also Angular2 + Jspm.io : reflect-metadata shim is required when using class decorators ). 然后,当我启动我的应用程序时,我收到要求“ reflect-metadata”的消息(另请参阅Angular2 + Jspm.io:使用类装饰器时,需要reflect-metadata shim )。 Installing this also via JSPM solves the issue. 也可以通过JSPM安装此解决方案。

But then I stumble on the next problem. 但是后来我偶然发现了下一个问题。 The ngFor is not giving me the expected behavior. ngFor没有给我预期的行为。 When I add records to a list of a component, it doesn't get updated. 当我将记录添加到组件列表时,它不会更新。 I tried adding them via click-event handlers and setTimeout, etc. but it doesn't seem to trigger the so called 'application tick'. 我尝试通过点击事件处理程序和setTimeout等添加它们,但似乎没有触发所谓的“应用程序滴答”。

After some digging through the code I found that: to have the ngFor update, you need to include zone.js since angular 2 depends on it. 在仔细研究代码后,我发现:要进行ngFor更新,您需要包含zone.js,因为angular 2依赖于它。 When it isn't there it is just silently ignored. 如果不存在,它只会被默默忽略。

So what you have to do is look at the dependencies that angular 2 got in its 'package.json' which are currently: 1. es6-promise 2. es6-shim 3. reflect-metadata 4. rxjs 5. zone.js 因此,您需要做的是查看angular 2在其“ package.json”中获得的依赖关系,这些依赖关系当前为:1. es6-promise 2. es6-shim 3. Reflection-metadata 4. rxjs 5. zone.js

Install all of them using JSPM and you should be good to go. 使用JSPM安装所有它们,您应该一切顺利。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM