Angular 2:
import { Injectable, Component, OnInit } from '@angular/core';
import { FormGroup, FormsModule, FormControl, Validators } from '@angular/forms'
import { Http, Response, Headers, HttpModule, RequestOptions, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
@Component({
selector: 'message-notofication',
templateUrl: './messageNotification.html',
styleUrls: ['./messageNotification.css']
})
@Injectable()
export class emailNotification {
constructor(private http:Http) { }
userForm = new FormGroup ({
msg_name: new FormControl(),
msg_details: new FormControl()
});
onFrmSubmit(){
let urlUpto = 'http://ncfkdevweb01/POSAlertWebService/api/';
let data = {
"NotificationID": "0",
"SubmitedEmail": "vasanth@gmail.com",
"PublishEmail": "vasanth1@gmail.com",
"ErrorEmail": "Telecom",
"Module": "1"
}
const headers = new Headers();
let body = JSON.stringify(data);
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Credentials', 'true');
headers.append("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
let options = new RequestOptions({headers: headers});
return this.http.put( urlUpto + "POSAlertEmailNotificiation/UpdateInsertNotificationEmail", body, options)
.subscribe(()=>{},
err =>console.log(err)
);
}
}
以上代码用于PUT service call
中的angular 2
。从服务器端,我们允许CORS
文件中的web.config
。
但我仍然无法修复此issue,例如显示“标头字段在预检响应中的Access-Control-Allow-Header不允许访问控制允许 - 来源