问题
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");
}
}
which was used in index.html
<dartcomp id="dc" val="x"></dartcomp>
Is there a way to access val in the constructor?
回答1:
Extend NgAttachAware
, implement the method attach()
and access your field there. When attach()
is called your val
is already properly initialized.
来源:https://stackoverflow.com/questions/21172775/is-it-possible-to-access-attributes-set-in-html-in-an-angular-dart-constructor