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

查看:23
本文介绍了是否可以在 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.

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

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