【发布时间】:2016-07-13 04:35:56
【问题描述】:
在修复如何导入添加到应用程序的文件夹后,我收到此错误。
我的应用结构
我的“app.ts”包括
import { bootstrap } from "@angular/platform-browser-dynamic";
import { Component,Inject } from "@angular/core";
import {JsonService} from "services";
import {Http,HTTP_PROVIDERS} from "@angular/http";
import {provide} from '@angular/core';
@Component({
selector: 'hello-world',
template: `
<div>
Hello world
</div>
`,
})
class HelloWorld {
constructor(@Inject(JsonService) private service :JsonService){
}
}
bootstrap(HelloWorld,[Http,HTTP_PROVIDERS,JsonService]);
我的服务
import {Injectable,Inject} from "@angular/core";
import {Http} from "@angular/http";
@Injectable
export class JsonService {
constructor(@Inject(Http) private http: Http) {
}
}
我的system.js.config文件如下
var map = {
'app': 'app',
'rxjs': 'node_modules/rxjs',
'@angular': 'node_modules/@angular',
'services': 'services',
'models': 'models'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'rxjs': { defaultExtension: 'js' },
'models': { main: 'index.js', defaultExtension: 'js' },
'services': { main: 'index.js', defaultExtension: 'js' }
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/testing',
'@angular/upgrade',
'services',
'models'
];
一开始我收到 404 错误,在修改 system.js 并添加服务和模型后我的服务丢失,我收到此错误
仍然得到这个 404
错误:无法解析“TypeDecorator”的所有参数(?)。确保所有参数都用 Inject 修饰或具有有效的类型注释,并且 'TypeDecorator' 用 Injectable 修饰
【问题讨论】:
标签: dependency-injection angular inject angular2-services