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

前端之家收集整理的这篇文章主要介绍了angular – 将组件属性绑定到输入的本机属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Angular 2的新人,我有以下问题.我试图将组件属性绑定到输入的本机属性(maxlength),我无法做到这一点.

代码如下:

textBox.ts

  1. @Component({
  2. selector: 'icb-textBox',inputs: [
  3. 'placeholder','mxlength','enabled','mandatory','description','type'],templateUrl: 'Common/Components/TextBox/textBox.html',styleUrls: ['Common/Components/TextBox/textBox.css']
  4. })
  5. export class TextBox {
  6.  
  7. private placeholder: string;
  8. private mxlength: number;
  9. private enabled: boolean;
  10. private mandatory: boolean;
  11. private description: string;
  12. private type: string;
  13. }

textBox.html

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

在’父亲’组件中:

  1. <icb-textBox placeholder="Name"
  2. mxlength="4"
  3. [mandatory]="false"
  4. [enabled]="true"
  5. description="Put your name">

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

谢谢.

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

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

猜你在找的Angularjs相关文章