这是一个在 Intellij15 上运行 typescript 的 angular2 项目。我已经导入了“rxjs/add/operator/map”,但仍然出现上述错误。
这是我的代码。我已经检查过其他类似的问题,但没有找到解决方案。
import {Component, OnInit} from "@angular/core";
import {Http} from "@angular/http";
import 'rxjs/add/operator/map';
@Component({
selector: "h-recommend",
template:`
<div>
hi
</div>
`
})
export class Recommendations implements OnInit{
constructor (private _http: Http){}
ngOnInit():any {
this._http.get('../jsonfile/guestRecommendations/1.json')
.map(res => res.json())
.subscribe((data) => {
this.hello();
alert(data);
});
}
hello(){
alert("hello");
}
}
由于它发生在编译时,我猜您没有 es6-shim / core-js 的类型。
你需要这个在你的typings.json
file:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654", // <-------
"jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
"node": "registry:dt/node#4.0.0+20160509154515"
}
}
您可以使用以下命令安装这些类型typings install
命令。
请参阅此页面了解更多详细信息:
- https://angular.io/guide/quickstart https://angular.io/guide/quickstart
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)