我正在使用toPromise()
,并且它在网站上工作正常但我在代码视图中遇到以下错误。
[
我怀疑它与我的本地模块有关。
组件的代码是
import "rxjs/Rx";
import './rxjs-extensions';
import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
@Injectable()
export class TokenValidatorService {
constructor(private http: Http) { }
validateToken(token: string): Promise<string> {
return this.http.get('/api/downloader/' + token + '/valid')
.toPromise()
.then(response => {
return response.text()
})
.catch(this.handleError);
}
getDownloadUrl(token: string, pin: string): Promise<string> {
return this.http.get('/api/downloader/' + token + '/' + pin + '/getlink')
.toPromise()
.then(response => {
return response.text()
})
.catch(this.handleError);
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error); // for demo purposes only
return Promise.reject(error.message || error);
}
}
我的package.json是
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2"
},
"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/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "^5.0.0-beta.12",
"systemjs": "0.19.27",
"zone.js": "^0.6.23"
}
}
我的systemjs.config.js是
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'https://unpkg.com/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.min.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.min.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.min.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.min.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.min.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.min.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.min.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.min.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});
})(this);
您会注意到我直接从unpkg
加载我怀疑这就是它在运行时工作的原因。这是一个VS项目VS它正在处理打字稿等,tsconfig.json是
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
修改
以下几页对此进行了讨论
https://github.com/ReactiveX/rxjs/issues/1696和https://github.com/Microsoft/TypeScript/issues/8518
我已升级到TS2,但我仍有问题。