是否可以在 angular.dart 构造函数中访问 HTML 中设置的属性?
问题描述:
我无法访问此组件构造函数中的属性 val
I cann´t access the attribute val in the constructor of this component
@NgComponent(
selector: 'dartcomp',
templateUrl: 'dartComp.html',
publishAs: 'ctrl',
map: const
{
'val' : '@val'
}
)
class DartComp
{ String val;
DartComp()
{ print("construktor DartComp $val");
}
}
在 index.html 中使用
which was used in index.html
<dartcomp id="dc" val="x"></dartcomp>
有没有办法在构造函数中访问val?
Is there a way to access val in the constructor?
答
扩展 NgAttachAware
,实现方法 attach()
并在那里访问您的字段.当 attach()
被调用时,您的 val
已经正确初始化.
Extend NgAttachAware
, implement the method attach()
and access your field there. When attach()
is called your val
is already properly initialized.