加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 将组件属性绑定到输入的本机属性

发布时间:2020-12-17 07:21:15 所属栏目:安全 来源:网络整理
导读:我是Angular 2的新人,我有以下问题.我试图将组件属性绑定到输入的本机属性(maxlength),我无法做到这一点. 代码如下: textbox.ts @Component({selector: 'icb-textbox',inputs: [ 'placeholder','mxlength','enabled','mandatory','description','type'],tem
我是Angular 2的新人,我有以下问题.我试图将组件属性绑定到输入的本机属性(maxlength),我无法做到这一点.

代码如下:

textbox.ts

@Component({
selector: 'icb-textbox',inputs: [
    'placeholder','mxlength','enabled','mandatory','description','type'],templateUrl: 'Common/Components/Textbox/textbox.html',styleUrls: ['Common/Components/Textbox/textbox.css']
})
export class Textbox {

    private placeholder: string;
    private mxlength: number;
    private enabled: boolean;
    private mandatory: boolean;
    private description: string;
    private type: string;
}

textbox.html

<input type="text" maxlength="{{mxlength}}" [(ngModel)]="value" placeholder="{{placeholder}}" [disabled]="!enabled"/>

在’父亲’组件中:

<icb-textbox placeholder="Name" 
                 mxlength="4" 
                 [mandatory]="false" 
                 [enabled]="true" 
                 description="Put your name">

属性’占位符’和’禁用’工作正常,但我可以使maxlength工作.
我尝试使用[maxlength]并得到此错误:无法绑定到’maxlength’,因为它不是已知的本机属性.

谢谢.

使用
[attr.maxlength]= 'your value'

因为默认的角度看属性绑定.告诉angular显式使用我们已经使用了这种语法

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读