Dart 角省道:组件的自动转换';s@来自属性的输入字段
假设Dart 角省道:组件的自动转换';s@来自属性的输入字段,dart,angular-dart,Dart,Angular Dart,假设 使组件状态如下的最佳方式是什么: @Component(... class Component{ List<String> listAttribute; // Should automatically contain [a,b,c] bool boolAttribute; // Should automatically contain true @组件(。。。 类组件{ List listAttribute;//应自动包含[a、b、c] bool boolatAtt
使组件状态如下的最佳方式是什么:
@Component(...
class Component{
List<String> listAttribute; // Should automatically contain [a,b,c]
bool boolAttribute; // Should automatically contain true
@组件(。。。
类组件{
List listAttribute;//应自动包含[a、b、c]
bool boolatAttribute;//应自动包含true
没有任何非角度的东西可以自动转换值
这种装订
list-attribute="a b c"
将始终传递字符串
可能的解决方案
首先,属性需要一个注释
@Input()List<String> listAttribute;
制作一个执行转换的setter
List<String> _listAttribute
@Input() set listAttribute(String value) {
_listAttribute = value?.split(' ');
}
或
或自定义管道来进行拆分
像
List<String> _listAttribute
@Input() set listAttribute(String value) {
_listAttribute = value?.split(' ');
}
list-attribute="a b c"
[list-attribute]="'a b c'"
[list-attribute]="a b c | split"