Angular2教程应用程序未加载(http部分)
我很难让本地代码在angular 2教程的http部分工作。更改为hero.service.ts后,在内存中包含DB服务后,它将停止工作。实际发生的情况是,应用程序只是拒绝加载,并卡在加载屏幕上。我已经找到了很多关于这个的帖子,但是没有一个能抓住我的问题。我仍然认为这与内存中的angular web api之类的东西有关。我不知道在哪里可以找到更多的细节,也不知道如何解决这个问题 systemjs.config.jsAngular2教程应用程序未加载(http部分),angular,Angular,我很难让本地代码在angular 2教程的http部分工作。更改为hero.service.ts后,在内存中包含DB服务后,它将停止工作。实际发生的情况是,应用程序只是拒绝加载,并卡在加载屏幕上。我已经找到了很多关于这个的帖子,但是没有一个能抓住我的问题。我仍然认为这与内存中的angular web api之类的东西有关。我不知道在哪里可以找到更多的细节,也不知道如何解决这个问题 systemjs.config.js /** * System configuration for Angular
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// 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.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.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);
package.json
{
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/angular/angular.io/blob/master/LICENSE"
}
],
"dependencies": {
"@angular/common": "~2.1.0",
"@angular/compiler": "~2.1.0",
"@angular/core": "~2.1.0",
"@angular/forms": "~2.1.0",
"@angular/http": "~2.1.0",
"@angular/platform-browser": "~2.1.0",
"@angular/platform-browser-dynamic": "~2.1.0",
"@angular/router": "~3.1.0",
"@angular/upgrade": "~2.1.0",
"angular-in-memory-web-api": "~0.1.5",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.3",
"typings":"^1.4.0"
}
}
内存中的-data.service.ts
import { InMemoryDbService } from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let heroes = [
{id: 11, name: 'Mr. Nice'},
{id: 12, name: 'Narco'},
{id: 13, name: 'Bombasto'},
{id: 14, name: 'Celeritas'},
{id: 15, name: 'Magneta'},
{id: 16, name: 'RubberMan'},
{id: 17, name: 'Dynama'},
{id: 18, name: 'Dr IQ'},
{id: 19, name: 'Magma'},
{id: 20, name: 'Tornado'}
];
return {heroes};
}
}
浏览器控制台显示:
08:16:31.929 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/traceur
patchProperty/desc.set/wrapFn@http://localhost:3000/node_modules/zone.js/dist/zone.js:698:26
ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:265:21
Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:154:28
ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:335:28
Error loading http://localhost:3000/traceur
Unable to load transpiler to transpile http://localhost:3000/node_modules/angular-in-memory-web-api/index.js
Error loading http://localhost:3000/node_modules/angular-in-memory-web-api/index.js as "angular-in-memory-web-api" from http://localhost:3000/app/app.module.js
Stack-Trace:
(SystemJS) XHR error (404 Not Found) loading http://localhost:3000/traceur
patchProperty/desc.set/wrapFn@http://localhost:3000/node_modules/zone.js/dist/zone.js:698:26
ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:265:21
Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:154:28
ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:335:28
Error loading http://localhost:3000/traceur
Unable to load transpiler to transpile http://localhost:3000/node_modules/angular-in-memory-web-api/index.js
Error loading http://localhost:3000/node_modules/angular-in-memory-web-api/index.js as "angular-in-memory-web-api" from http://localhost:3000/app/app.module.js1localhost:3000:16:49
<anonym>localhost:3000:16
ZoneDelegate.prototype.invoke()zone.js:232
Zone.prototype.run()zone.js:114
scheduleResolveOrReject/<()zone.js:502
ZoneDelegate.prototype.invokeTask()zone.js:265
Zone.prototype.runTask()zone.js:154
drainMicroTaskQueue()zone.js:401
ZoneTask/this.invoke()zone.js:339
08:16:31.929错误:(SystemJS)XHR错误(404未找到)加载http://localhost:3000/traceur
patchProperty/desc.set/wrapFn@http://localhost:3000/node_modules/zone.js/dist/zone.js:698:26
ZoneDelegate.prototype。invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:265:21
区域。原型。runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:154:28
ZoneTask/这个。invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:335:28
加载错误http://localhost:3000/traceur
无法将Transbiler加载到Transbilehttp://localhost:3000/node_modules/angular-内存中的web api/index.js
加载错误http://localhost:3000/node_modules/angular-内存中web api/index.js作为“内存中的角度web api”,来自http://localhost:3000/app/app.module.js
堆栈跟踪:
(SystemJS)XHR错误(404未找到)加载http://localhost:3000/traceur
patchProperty/desc.set/wrapFn@http://localhost:3000/node_modules/zone.js/dist/zone.js:698:26
ZoneDelegate.prototype。invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:265:21
区域。原型。runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:154:28
ZoneTask/这个。invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:335:28
加载错误http://localhost:3000/traceur
无法将Transbiler加载到Transbilehttp://localhost:3000/node_modules/angular-内存中的web api/index.js
加载错误http://localhost:3000/node_modules/angular-内存中web api/index.js作为“内存中的角度web api”,来自http://localhost:3000/app/app.module.js1localhost:3000:16:49
本地主机:3000:16
ZoneDelegate.prototype.invoke()zone.js:232
Zone.prototype.run()Zone.js:114
ScheduleSolveorReject/我对这个内存中的web api有很多问题,如果不是为了教程,我宁愿完全避免它。我认为弹出一个简单的后端并进行实际测试比处理它更容易
我遇到的问题是通过引用库的一个精确版本解决的,我恐怕记不起是哪个版本了,但您可以在这里尝试0.0.10。您可以在package.json中引用所需的版本(请确保引用准确的版本,即不带“~”)
如果这对我没有帮助,我可以试着在以后找出哪个版本适合我。您还可以在控制台中检查错误,因为您可能还有其他一些问题。我对这个内存中的web api有很多问题,如果不是为了本教程,我宁愿完全避免它。我认为弹出一个简单的后端并进行实际测试比处理它更容易
我遇到的问题是通过引用库的一个精确版本解决的,我恐怕记不起是哪个版本了,但您可以在这里尝试0.0.10。您可以在package.json中引用所需的版本(请确保引用准确的版本,即不带“~”)
如果这对我没有帮助,我可以试着在以后找出哪个版本适合我。您还可以在控制台中检查错误,因为您可能还有其他一些问题。这是因为版本“angular in memory web api”中的~
:“~0.1.5”
获取了最新的修补程序版本,当前为0.1.13
。自0.1.5
以来,我们对加载模块的方式进行了突破性的更改
见
转到umd
更改systemjs.config
和导入库的方式
在systemjs.config.js
中,应将映射更改为:
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
然后从包中删除:
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
您必须按如下方式导入内存模块中(通常在AppModule中):
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
这是因为“angular in memory web api”版本中的~
:“~0.1.5”
获取了最新的补丁版本,目前是0.1.13
。自0.1.5
以来,我们对加载模块的方式进行了突破性的更改
见
转到umd
更改systemjs.config
和导入库的方式
在systemjs.config.js
中,应将映射更改为:
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
然后从包中删除:
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
您必须按如下方式导入内存模块中(通常在AppModule中):
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
您是否在NgModule
中添加了HttpModule
?是否可以看到任何控制台错误和post(如果有)?您是否在NgModule
中添加了HttpModule
?是否可以看到任何控制台错误和post(如果有)?这对我不起作用。应用自述文件中提到的更改后,我在npm启动后收到以下输出:npm start>angular-quickstart@1.0.0start/home/maik/repos>tsc&同时“tsc-w”“lite server”app/main.ts(1,1):错误TS6053:找不到文件“/home/maik/repos/app/node_modules/angular2/typings/browser.d.ts”。node_modules/@types/core js/index.d.ts(21,14):错误TS2300:重复标识符'PropertyKey'。node_modules/@types/core js/index.d.ts(1513,5):错误TS2300:重复标识符“export=”…依此类推。
这对我不起作用。应用自述文件中提到的更改后,我在npm启动后收到以下输出:npm start>angular-quickstart@1.0.0启动/主/主/主/回购>tsc和同时“tsc-w”lite se