在这里,我正在从组件中获取复选框列表
<div class="checkbox" *ngFor="let m of modelupdatecurrencycheckbox">
<input class="form-check-input"
(change)="updatecurrencyselect(m.name)"
[(ngModel)]="m.checked" name="{{ modelupdatecurrencycheckbox.name }}"
type="checkbox" id="{{m.name}}"
[ngModelOptions]="{standalone: true}">
<label class="form-check-label" for="{{m.name}}">
{{m.name}}
</label>
</div>
<div class="container">
<button type="button" class="btn btn-primary waves-effect" (click)="onSubmitupdatecurrencyCheckbox()">SAVE</button>
</div>
<input type="text" [(ngModel)]="added">
<button class="btn btn-primary" (click)="addedinput()">add</button>
数组正在推送,但数组未发布:
added:any=""
updatecurrencycheckbox:any={ tablename:"updatecurrency" };
modelupdatecurrencycheckbox = [
{
name: 'INR ',
checked: false,
},{
name: 'USD ',
checked: false
},{
name: 'Euro ',
checked: false,
},{
datasas:[]
}];
addedinput(){
this.datasas = this.modelupdatecurrencycheckbox
.push(
{
name: this.added,
checked: false
});
console.log("sda" + JSON.stringify(datasas))
}
onSubmitupdatecurrencyCheckbox(){
var data = {
array:this.modelordercurrencycheckbox,
tablename:"updatecurrency"
}
this.dataService.postcustomertablepreferences(data).subscribe(
(response) => console.log(response),
(error) => console.log(error)
);
}
使用API URL在MongoDB中发布数据的服务:
import {Injectable} from '@angular/core'
import {Http, URLSearchParams, RequestOptions, Response, ResponseContentType } from '@angular/http'
import 'rxjs/add/operator/map'
import {HttpHeaders, HttpClient} from '@angular/common/http'
import 'rxjs/add/operator/toPromise';
import { environment } from '../../../environments/environment';
@Injectable()
export class adminservice{
constructor (public _http:Http, public http:HttpClient){}
private url2="/api/users/savepreferences";
private url3="/api/users/fetchpreferences";
postcustomertablepreferences(modelcheckbox){
return this._http.post(this.url2, modelcheckbox, {withCredentials:true}).map(res=>res.json());
}
getpreferences(data){
return this._http.post(this.url3, data, {withCredentials:true}).map(res=>res.json());
}
}
我在将数组推入modelupdatecurrency并尝试发布时遇到了问题。
答案 0 :(得分:0)
curl -X POST \
https://login.windows.net/<tenant>/oauth2/token \
-H 'Accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=password&scope=openid&resource=<resourceUri>&client_id=<yourClientId>&client_secret=<clientSecret>&username=<username>&password=<password>'
this.datasas = this.modelupdatecurrencycheckbox.push()
方法返回一个新的数组长度。
请参阅此link。
push()
-代替此,使用:
console.log("sda" + JSON.stringify(datasas))