以下是使用RC1的代码:
ngOnInit(){
var id = this._routeParams.get("id");
this.title = id ? "Edit User" : "New User";
if (!id)
return;
this._slugService.getSlug(id)
.subscribe(
slug => this.slug = slug,
response => {
if (response.status == 404) {
this._router.navigate(['NotFound']);
}
});
}
onSubmit(){
this.dd = 'YAY';
//console.log('adfasdf');
/*
this._slugService.addSlug(this.form.value)
.subscribe(x => {
// Ideally, here we'd want:
// this.form.markAsPristine();
this._router.navigate(['Slugs']);
});
*/
var result:any;
if (this.slug.id)
result = this._slugService.updateSlug(this.slug);
else
result = this._slugService.addSlug(this.slug)
/*PROBLEM IS HERE!!!!*/
result.subscribe(x => {
this._router.navigate(['Slugs']);
});
}
对于变量x我得到以下
Parameter 'x' implicitly has 'any' type
app/slugs/slug-form.component.ts(98,1): error TS1128: Declaration or statement expected.
npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/Cellar/node/6.2.0/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.2.0
npm ERR! npm v3.8.9
npm ERR! code ELIFECYCLE
npm ERR! angular2-quickstart@1.0.0 start: `tsc && concurrently "tsc -w" "lite-server" `
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular2-quickstart@1.0.0 start script 'tsc && concurrently "tsc -w" "lite-server" '.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc && concurrently "tsc -w" "lite-server"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-quickstart
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
如果我注释掉我的应用程序启动的代码。我该如何解决?
以下是返回的"结果"从控制台:
Observable {_isScalar: false, source: Observable, operator: MapOperator}_isScalar: falseoperator: MapOperatorproject: (res)arguments: (...)caller: (...)length: 1name: ""prototype: Object__proto__: ()<function scope>thisArg: undefined__proto__: Objectcall: (subscriber, source)constructor: MapOperator(project, thisArg)__proto__: Objectsource: Observable_isScalar: false_subscribe: (responseObserver)__proto__: Object__proto__: Object_subscribe: (subscriber)constructor: Observable(subscribe)forEach: (next, PromiseCtor)lift: (operator)map: map(project, thisArg)subscribe: (observerOrNext, error, complete)Symbol(Symbol.observable): ()__proto__: Object
当我转到订阅者时,我看到了这个错误:
[Exception: TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context. at Function.remoteFunction (<anonymous>:3:14) at Object.InjectedScript.callFunctionOn (<anonymous>:124:124)]
caller
:
(...)
length
:
1
name
:
""
prototype
:
Object
__proto__
:
()
<function scope>
__proto__
:
Object
__proto__
:
Object
_subscribe
:
(subscriber)
constructor
:
Observable(subscribe)
forEach
:
(next, PromiseCtor)
lift
:
(operator)
map
:
map(project, thisArg)
subscribe
:
(observerOrNext, error, complete)
Symbol(Symbol.observable)
:
()
__proto__
:
Object
答案 0 :(得分:0)
在tsconfig.json
添加:
{
...
"compilerOptions": {
...
"noImplicitAny": false
...
}
...
}
这将解决x
变量的问题。