Я хочу обновить информацию о пользователе, используя метод Http put, но он продолжает возвращаться
detail: "Authentication credentials were not provided
Вот мой 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);
}
}
}
и мой код storeService.ts
@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'];
})
};
Интересно, где я ошибаюсь, так как конечная точка API ожидает storeId в запросе ... все это выглядит хорошо в моих глазах, но опять же ... Можете ли вы помочь мне определить ошибку или провести меня правильно? путь
обновление с помощью 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>