2
以下のエラーが発生しました。getterのみを持つ[objectオブジェクト]のプロパティスタックを設定できません。
はPlunkerがここ https://plnkr.co/edit/IP1ssat2Gpu1Cra495u2?p=preview
コードでのみゲッター
を持っている[オブジェクトのオブジェクト]のプロパティスタックを設定することはできません以下のとおりである。
//our root app component
import {Component, NgModule, OnInit, Injectable} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import { HttpModule, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
class MyModel {
public name: string;
public value: string;
}
@Injectable()
export class MyService {
constructor(public http: Http) {
}
getData (request: MyModel):Promise<MyModel>{
return this.http.get('https://run.plnkr.co/j2Cw0yaD5Dn7ENaR/mymodel.json')
.toPromise()
.then(response => {
return response as MyModel;
});
}
}
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
</div>
`,
})
export class App implements AfterViewInit {
name:string;
constructor(myService : MyService) {
this.name = 'Angular2'
}
ngAfterViewInit(){
let myModelObj : MyModel = new MyModel();
console.log(this.myService);
this.myService.getData(myModelObj)
.then(response => {
console.log('GET Request success')
console.log(response);
});
}
}
@NgModule({
imports: [ BrowserModule, HttpModule ],
declarations: [ App ],
providers : [MyService],
bootstrap: [ App ]
})
export class AppModule {}
更新
0私はそれが正常に動作しているこの4行をコメントする場合私はエラーを理解することができていますが、ここで
this.myService.getData(myModelObj)
.then(response => {
console.log('GET Request success')
console.log(response);
});
です。助けてください。
プライベートキーワードのみが2時間かかります。 :( –