我想通过角度2中的路径调用页面
在我的app.modules中,我使用了RouterModule和Routes,看起来不错:
...
import { RouterModule, Routes } from '@angular/router';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { DashBoardComponent} from './dashboard/dashboard.component';
import { NotFoundComponent } from './not-found/not-found.component';
const APPROUTES: Routes = [
{path: 'home', component: AppComponent},
{path: 'login', component: LoginComponent},
{path: 'dashboard', component: DashboardComponent},
{path: '**', component: NotFoundComponent}
];
@NgModule({
declarations: [
AppComponent,
LoginComponent,
DashboardComponent
NotFoundComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterialModule.forRoot(),
RouterModule.forRoot(APPROUTES)
],
providers: [],
bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)
在这里,我创造了一个常数
import { RouterModule, …Run Code Online (Sandbox Code Playgroud) 我有一种表单,需要将字段设置为有效或无效,因为我想编辑用户,但按钮保持禁用状态
编辑组件
ngOnInit() {
this.getForm();
this.getRole();
console.log(this.formGroup.valid)
}
getForm() {
this.formGroup = this.formBuilder.group({
name: ['', Validators.required],
label: ['', Validators.required],
});
}
Run Code Online (Sandbox Code Playgroud)
当我进入页面编辑时,我希望能够将按钮设置为无效表单
<button type="submit" mat-button color="primary" [disabled]="!formGroup.valid">Alterar</button>
Run Code Online (Sandbox Code Playgroud)
例如
if(user) {
this.formGroup (invalid)
} else {
this.formGroup (valid)
}
Run Code Online (Sandbox Code Playgroud)
这是我编辑项目的页面,但即使填写了字段,表单组也无效,为什么?