这是我简单的test.html文件,我想将employeeId传递给localhost:4200 / homePage。当我使用get方法时,它可以正常工作,但帖子出现错误,无法发布
log file
在homePage-component.ts文件中,我正在使用此代码-
var count = 0
describe('Main suite', function () {
this.retries(5)
it('Some setup', () => {
console.log('1. Some setup');
});
it("bail issue", function() {
console.log('2. bail issue');
if (count < 4) {
count += 1
throw new Error("Must be retried")
}
})
});
describe('end', function () {
it('close', () => {
});
});
答案 0 :(得分:1)
基本上,您希望在提交后将数据从 page1 component
发送到 page2 component
和route
到Angular中的该组件的形式。
您应使用(ngSubmit)
可用的Angular
指令
尝试进行以下更改:
page1.component.html
<form (ngSubmit)="formSubmit()">
<input type="text" name="employeeID" value="" id="apiUrl" id="employeeID" [(ngModel)]="empId" />
<button type="submit">Submit</button>
</form>
page1.component.ts
empId = "";
constructor(private router : Router) {}
formSubmit(){
this.router.navigate(['/home',{queryParameter : {employeeId : this.empId}}])
}
home.component.html
<div>{{employeeId}}</div>
home.component.ts
employeeId : String
constructor(private route : ActivatedRoute) {}
ngOnInit(){
this.route.queryParamters.subscribe(data=>{
this.employeeId = data['employeeId']
})
}
您还需要在应用程序中定义路由。 查看官方docs了解更多信息。