I want to update user information using the Http put method but it keeps returning
detail: "Authentication credentials were not provided
Here is my editComponent.ts
export class MyProfileEditComponent implements OnInit {
store: any = {};
editProfileForm: FormGroup;
private formSubmitAttempt: boolean;
constructor(fb: FormBuilder, public storeSrv: StoreService) {
this.editProfileForm = fb.group({
'mobile': [''],
'address': [''],
'description': [''],
'storeUserId': [''],
});
}
editProfile() {
this.formSubmitAttempt = true;
if (this.store.mobile || this.store.address || this.store.description) {
this.storeSrv.editStore(this.store.mobile, this.store.address, this.store.description, this.store.storeUserId);
}
}
}
and my storeService.ts code
@Injectable()
export class StoreService {
public updateStoreUrl = this.globals.UPDATE_STORE_URL
store: any = {};
storeId: any;
constructor(private http: Http, private router: Router, private globals: Globals) { }
editStore(mobile: string, address: string, description: string, storeId: any) {
let tempStore = localStorage.getItem('store');
if (tempStore) {
this.store = JSON.parse(tempStore);
this.storeId = this.store.user;
}
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.put(this.updateStoreUrl + this.storeId + '/', {
headers })
.subscribe(res => {
let msg = JSON.parse(res['_body'])['message'];
}, error => {
let msg = JSON.parse(error._body)['message'];
})
};
I wonder where i am getting this wrong as the api endpoint is expecting the storeId in the request...it all looks good in my eyes but then again...Can you help me spot the error or lead me through right path?
update with editComponent.html
<form [formGroup]="editProfileForm" (ngSubmit)="editProfile()" novalidate>
<div class="row">
<div class="col-md-6">
<div class="form-group has-feedback" style="position: relative;">
<label for="storename">Store Name</label>
<input type="text" name="storename" class="form-control" placeholder="{{store.name}}" disabled>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback" style="position: relative;">
<label for="mobilenumber">Mobile Number</label>
<input type="text" name="mobilenumber" class="form-control" placeholder="{{store.mobile}}" [(ngModel)]="store.mobile" [formControl]="editProfileForm.controls['mobile']">
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback" style="position: relative;">
<label for="address">Store Address</label>
<textarea name="address" id="" cols="30" rows="10" class="form-control" placeholder="{{store.address1}}"></textarea>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback" style="position: relative">
<label for="description">Store Description</label>
<textarea name="description" id="" cols="30" rows="10" class="form-control" placeholder="{{store.description}}"></textarea>
</div>
</div>
<input type="text" name="storeUserId" [(ngModel)]="store.userId" [formControl]="editProfileForm.controls['storeUserId']" value="{{store.user}}" hidden>
<div class="btn-container" style="float: right; margin-right: 15px;">
<button class="btn btn-accent btn-flat b-r-10">Edit Profile</button>
</div>
</div>
</form>