是否可以访问在angular.dart构造函数中的HTML中设置的属性? [英] is it possible to access attributes set in HTML in an angular.dart constructor?

查看:216
本文介绍了是否可以访问在angular.dart构造函数中的HTML中设置的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法访问此组件的构造函数中的属性val

  @NgComponent (
selector:'dartcomp',
templateUrl:'dartComp.html',
publishAs:'ctrl',
map:const
{
' val':'@val'
}

class DartComp
{String val;

DartComp()
{print(construktor DartComp $ val); $ {
}
}



 < dartcomp id =dcval =x>< / dartcomp> 

有没有办法在构造函数中访问val?

,执行 attach() c> 并访问你的领域。当 attach()被调用时,您的 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");
  }
}

which was used in index.html

<dartcomp id="dc" val="x"></dartcomp>

Is there a way to access val in the constructor?

解决方案

Extend NgAttachAware, implement the method attach() and access your field there. When attach() is called your val is already properly initialized.

这篇关于是否可以访问在angular.dart构造函数中的HTML中设置的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆