我遇到了一个奇怪的情况,其中Everynow然后我的角应用程序似乎做了一些随机重定向。
我有一个笔记部分,当你添加一个新笔记时,它应该将笔记添加到笔记列表中(代码中没有重定向)。但由于某些原因,当用户首次登录并创建他们的第一个音符时(这只发生在第一个音符上,所有连续音符都按预期工作)。
重定向还会在网址<<
此http://localhost:4200/phils-test-team/goals?body=redirects%2Bto%2Bgoals&title=&title=
不在代码中。
当我检查我的控制台并启用路线追踪时,所有看起来都是正确的。
我想问题是,角度中是否有特定的东西可以影响重定向,或者可能导致重定向而不在代码中指定它们。
新-Note.Component
?body=redirects%2Bto%2Bgoals&title=&title=
App.Routes
@Component({
selector: 'new-note',
templateUrl: './new-note.component.html',
styleUrls: ['./new-note.component.styl']
})
export class NewNoteComponent implements OnInit, OnChanges {
@Input() initialValue:any;
experiment_id: string;
goal_id: string;
user_id: string;
team_id: string;
form: FormGroup;
date_created: any;
isActive = false;
constructor(
private fb: FormBuilder,
private route: ActivatedRoute,
private notesService: NotesService,
private usersService: UsersService
) {}
ngOnInit() {
this.isActive = false;
this.date_created = new Date();
this.route.parent.data.map((d: any) => d.experiment).subscribe((experiment: any) => {
this.user_id = experiment.user_id;
this.team_id = experiment.team_id;
this.goal_id = experiment.goal_id;
this.experiment_id = experiment.$key;
});
this.form = this.fb.group({
body: ['',Validators.required],
date_modified: new Date(),
customer: [''],
company: ['']
// rating: ['',Validators.required]
});
console.log(this.form);
}
ngOnChanges(changes:SimpleChanges) {
if (changes['initialValue']) {
this.form.patchValue(changes['initialValue'].currentValue);
this.experiment_id = this.team_id;
}
}
isErrorVisible(field:string, error:string) {
return this.form.controls[field].dirty
&& this.form.controls[field].errors &&
this.form.controls[field].errors[error];
}
reset() {
this.form.reset();
}
get valid() {
return this.form.valid;
}
get value() {
return this.form.value;
}
// Toggle Add Note
onToggleAddNote() {
this.isActive = !this.isActive;
event.preventDefault();
}
save(form, onToggleAddNoteInActive) {
this.notesService.createNewNote(this.team_id, this.user_id, this.goal_id, this.experiment_id, form.value, this.date_created)
.subscribe(
() => {
// alert("note created succesfully. Create another note ?");
form.reset();
this.isActive = false;
},
err => alert(`error creating note ${err}`)
);
}
}
更新: 我注意到它实际上是在获取表单的内容并将其添加到URL中。
export const routerConfig: Route[] = [
{
path: 'teams/new',
component: NewTeamComponent
},
{
path: 'home', redirectTo: '/login'
},
{
path: ':team-name',
canActivate: [AuthGuard],
component: AppComponent,
resolve: {
team: TeamResolver
},
children: [
{
path: 'goals',
children: [
{ path: ':goal_id', component: SingleGoalComponent,
resolve: {
goal: GoalResolver
},
children: [
{ path: 'experiments/new', component: NewExperimentComponent },
{ path: 'experiments/:experiment_id',
resolve: {
experiment: ExperimentResolver
},
children: [
{ path: 'edit', component: EditExperimentComponent,
},
{ path: '', component: ExperimentDetailsComponent,
children: [
{ path: 'notes', component: ExperimentNotesComponent },
{ path: '', component: BlankNotesComponent }
]
}
]
},
{ path: '', component: ExperimentsComponent }
]
},
{ path: '', component: GoalsComponent }
]
},
{ path: 'notes', component: NotesComponent }
]
},
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: '**', redirectTo: 'home' }
];
更新: 新note.component.html
http://localhost:4800/phils-test-team/goals?body=new%2Bgoal%2Bshould%2Bbe%2Badded%2Bwith%2Bout%2Bany%2Bproblems&title=&title=