1
私は角2を使い慣れていません。 Angular 2 Tutorial (2016) - Servicesエラーを解決する方法角度2の注射可能物で装飾された 'X'のすべてのパラメータを解決できません。
しかし、私は 'ContactListComponent' のすべてのパラメータを解決できません
エラー
を取得しています(?)。 すべてのパラメータがInjectで装飾されているか、有効な型式を持っていることを確認してください
どうすれば問題を解決できますか?
私のコードは
contact.ts
export interface Contact {
firstname : string,
lastname : string,
address : string
}
モックcontact.ts
import {Contact} from "./contact";
export const CONTACTS: Contact[] =[
{firstname : "John", lastname : "A", address : "john home"},
{firstname : "David", lastname : "B", address : "david home"},
{firstname : "Johnson", lastname : "C", address : "Johny home"},
{firstname : "Bobby", lastname : "D", address : "Bobby home"},
];
contact.service.ts
import { Injectable } from 'angular2/core';
import { CONTACTS } from "./mock-contact";
@Injectable()
export class ContactService {
getContacts(){
return Promise.resolve(CONTACTS);
}
}
コンタクトリストの下に与えられています.component.ts
import {Component} from 'angular2/core';
import {ContactComponent} from "./contact.component";
import { ContactService } from './contact.service';
import {Contact} from './contact';
import {OnInit} from 'angular2/core';
@Component({
selector : "contact-list"
template : `
<ul>
<li *ngFor="#contact of contacts"
(click)="onSelect(contact)" [class.clicked] =" selectedContact === contact">
{{contact.firstname}}s App
</li>
</ul>
<contact [contact]="selectedContact"></contact>
`,
styleUrls: ["../src/css/app.css"],
providers : [ContactService]
directives : [ContactComponent],
})
export class ContactListComponent implements OnInit {
public contacts : Contact[];
public selectedContact = {};
constructor(private _contactService: ContactSevice) {}
onSelect(contact){
this.selectedContact = contact;
}
getContacts(){
this._contactService.getContacts().then((contacts:Contact[]) => this.contacts = contacts)
}
ngOnInit():any{
this.getContacts();
}
}
この問題を解決するお手伝いはありますか?私は本当にこの問題に固執しています。
どうもありがとう...私のミス(
r
を逃す)..する必要があります。 – manoos心配なし:D。 。 –