我有一张表格。
<form class="row" style="width: 100%" (ngSubmit)="inf()">
<div class="col-md-12">
<div class="form-group col-md-4">
<label for="cups">Yep</label>
<input type="text" class="form-control" id="data" [(ngModel)]="data"
[ngModelOptions]="{standalone: true}" value="1">
</div>
</div>
<div class="col-md-6">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
具有inf功能的组件数据
import {Component} from '@angular/core';
import {HttpClient} from '@angular/common/http';
@Component({
selector: 'app-info',
styleUrls: ['./info.component.css'],
templateUrl: './info.component.html'
})
export class DataComponent {
public data: string = '1';
public info;
constructor(private http: HttpClient) {
}
inf() {
console.log("Working");
this.http.get('http://xxxxxxxx/data/' + this.data, {responseType: 'json'}).subscribe(res => {
if (Object.keys(res).length > 0) {
this.info = res;
} else {
this.info = null;
}
});
return false;
}
}
如果我重新加载网站并尝试搜索,则无法正常工作。 (不要在终端上显示“工作”)
仅当我使用内部链接routerLink =“”
转到此模板时才有效路线
const routes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: 'panel', loadChildren: './panel/panel.module#PanelModule' , canActivate: [AuthGuard]},
{ path: '', redirectTo: 'panel', pathMatch: 'full' },
{ path: '**', redirectTo: 'panel' },
];