我的表格
public loginForm = new FormGroup({
username: new FormControl('', [Validators.required]),
password: new FormControl('', [Validators.required, Validators.minLength(8)]),
});
Run Code Online (Sandbox Code Playgroud)
当获取表单的值时,这是它的类型
getRawValue(): {
username: string | null;
password: string | null;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样做来抑制空值
public loginForm = new FormGroup({
username: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
password: new FormControl('', { nonNullable: true, validators: [Validators.required, Validators.minLength(8)] }),
});
Run Code Online (Sandbox Code Playgroud)
但是有没有办法让所有表单控件默认都不可为空呢?
如果我的表单包含很多控件,我将不得不使用 nonNullable: true所有控件
如何在新的 TextButton 中添加给定高度并使其角变圆
这是在现已弃用的 FlatButton 中执行此操作的方法。
FlatButton(
height: 44,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)),
color: Colors.green[900],
minWidth: double.infinity,
onPressed: () => cart.gtynAddToCart(productID),
child: Text(
'Button',
style: TextStyle(color: Colors.white),
));
Run Code Online (Sandbox Code Playgroud) 问题是在隐藏它之后,当我通过顶部滑动将它带回来然后保持......
我该如何解决这个问题?也许某种监听器触摸顶部状态栏?
我的代码
class _MyProfileState extends State<MyProfile> {
@override
void initState() {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
super.initState();
}
@override
void dispose() {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My Profile'),
elevation: 0,
),
body: Container(),
);
}
}
Run Code Online (Sandbox Code Playgroud) 我不能使用,TextEditingController因为TextFormField使用Autocomplete fieldViewBuilder TextEditingController
Autocomplete(
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') return [];
return this
.productNames
.where((Map<String, dynamic> option) {
return option['ar']
.toLowerCase()
.contains(textEditingValue.text.toLowerCase());
});
},
fieldViewBuilder: (context, textEditingController,
focusNode, onFieldSubmitted) =>
TextFormField(
controller: textEditingController,//uses fieldViewBuilder TextEditingController
focusNode: focusNode,
),
),
Run Code Online (Sandbox Code Playgroud) 使用flutter_staggered_grid_view我会得到我不想要的 GRID 1 。
相反,我希望如果BOX 1的高度为 80px,BOX 2的高度为 50px。Box 2 应该将自身扩展为 80px。
而且高度是动态的。
我收到这个错误
属性绑定 ngIf 未被嵌入模板上的任何指令使用。确保属性名称拼写正确并且所有指令都列在“@NgModule.declarations”中
即使你在我跑步时也能正常工作ng serve。
当我将 Angular 更新为v13.
我已经尝试重新启动Vscode并重新安装Angular Language Service并安装以前版本的Angular Language Service ...它们都不起作用..
我的app.module.ts:
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [CommonModule, BrowserModule, AppRoutingModule],
providers: [],
bootstrap: [AppComponent],
exports: [CommonModule, BrowserModule],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud) 如何使自动完成框与TextField没有特定宽度的自动完成框大小相同,它占用最大宽度。
Autocomplete(
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return ['aa', 'bb', 'cc', 'aa', 'bb', 'cc'];
}
return ['aa', 'bb', 'cc', 'aa', 'bb', 'cc']
.where((String option) {
return option
.toString()
.contains(textEditingValue.text.toLowerCase());
});
},
onSelected: (option) {
print(option);
},
),
Run Code Online (Sandbox Code Playgroud)