Reputation: 51
I try to send the selected item value "c[3]" using angular 2. What I want is : When I select an item, the details about that item are displayed. Then I click in submit to send this value and wait for a reply. My problem is in the second part, I can not send the selected item through the form. An error is displayed when I try the code I have written:
inline template:14:8 caused by: No provider for standard!
selectedinput.html
<form (ngSubmit)="onSubmit(f.value)" >
<form (ngSubmit)="onSubmit(f)" #f="ngForm">
<div class="form-group">
<div class="form-group">
<label for="exampleSelect1">Example select</label>
<select class="form-control" [(ngModel)] = "selection2" (change)="selectionChanged()" name="addresseAdmin" >
<option *ngFor="let c of users" [ngValue]="'E-mail : '+c[2] +' '+'@: '+ c[4]" > {{c[0]}} {{c[1]}}</option>
</select>
<br> {{selection2}}
</div>
</div>
</form>
selectedinput.component.ts
constructor(public adminService :adminService,private standard:
standard) {}
ngOnInit() {
this.adminService.getData().subscribe(response=>{
this.users=response.users,console.log(this.users)
});
}
onSubmit(form: NgForm) {
this.standard.create(this.addresseAdmin)
.subscribe(response=>{console.log("response",response);
})
}
sendreponse.service.ts
@Injectable()
export class standard {
handleError: any;
private Url ='http://localhost:3000/register/permission';
constructor (private http: Http) {}
private extractData(res: Response) {
let body = res.json();
return body || { };
}
create(addresseAdmin): Observable<any> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.Url, addresseAdmin, options)
.map(this.extractData);
}
}
I want to send only the c[2] value in the form knowing that my data are stocked in an array!
Upvotes: 0
Views: 170
Reputation: 11398
You need to add your standard class into the providers of your module :
import {standard} from 'somewhere/over/the/rainbow'
@NgModule({
providers: [
standard
]
})
Upvotes: 4