【发布时间】:2018-04-24 11:42:29
【问题描述】:
我正在尝试从主页获取参数这是表单代码。数据已经传递给函数(选择)。
<form #f="ngForm" (ngSubmit)="Select(f.value)">
<ion-input placeholder="Student ID" type="text" name="Studentid" ngModel></ion-input>
<ion-input placeholder="Subject ID" type="text" name="Subjectid" ngModel></ion-input>
<input type="submit"/>
</form>
这是我的ts代码
export class HomePage {
users:any;
constructor(public navCtrl: NavController,public http :Http) {
}
这是我的功能。这些值是从表单传递的,而不是传递给 url 参数,但在 console.log 中的值正在打印。
Select(data) {
var stuid= data.Studentid;
var subid = data.Subjectid;
if(stuid && subid != null)
{
console.log(stuid);
console.log(subid);
this.http.get("http://localhost:8100/Service1.svc/RestService/Checkstudent/{0}/{1}",stuid,subid)
.map(res => res.json())
.subscribe(res => {
this.users = res;
}, (err) => {
alert("failed loading json data");
});
}
}
这是网络日志中执行函数的结果
请求网址: http://localhost:8100/Service1.svc/RestService/Checkstudent/%7B0%7D/%7B1%7D
这个错误也出现在开头
预期 1-2 个参数,但得到 3 个 符合 this.http.get("http://localhost:8100/Service1.svc/RestService/Checkstudent/{0}/{1}",stuid,subid)
【问题讨论】:
-
这个错误是不言自明的。您想对 http 调用中的 url 做什么?
-
获取数据到主页作为列表
-
已经完成但手动将数据分配给 URL 像这样 (localhost:8100/Service1.svc/RestService/Checkstudent/D51E8459/…) 但我需要使用表单获取这些参数
标签: json forms url ionic-framework get