Angular 4, <md-checkbox> 没有双向绑定

bre*_*one 2 checkbox angular

我在 HTML 中有一个复选框,如下所示,并希望与 ts 中的变量进行双向绑定:

...
        </md-grid-tile>
        <md-grid-tile class="grid-box-row"> 
            <md-checkbox ng-model="item.exportable">{{item.exportable}}
            </md-checkbox>
        </md-grid-tile>        
    </div>
    </ng-container>
</md-grid-list>
Run Code Online (Sandbox Code Playgroud)

item.exportable 是在 ts 中定义的布尔值:

exportable: boolean;
Run Code Online (Sandbox Code Playgroud)

它显示如下: 在此处输入图片说明

即使值为真,它也不会被检查。并且点击UI上的复选框不会影响复选框后显示的值。请帮忙。谢谢。


谢谢大家的回复。添加方括号和括号对后:

       </md-grid-tile>
        <md-grid-tile class="grid-box-row"> 
            <md-checkbox [(ng-model)]="item.exportable">{{item.exportable}}
            </md-checkbox>
        </md-grid-tile>        
    </div>
    </ng-container>
</md-grid-list>
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Unhandled Promise rejection: Template parse errors:
Can't bind to 'ng-model' since it isn't a known property of 'md-checkbox'.
1. If 'md-checkbox' is an Angular component and it has 'ng-model' input, then verify that it is part of this module.
2. If 'md-checkbox' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
        </md-grid-tile>
        <md-grid-tile class="grid-box-row"> 
            <md-checkbox [ERROR ->][(ng-model)]="item.exportable">{{item.exportable}}
            </md-checkbox>
        </md-grid-til
Run Code Online (Sandbox Code Playgroud)

我在 app.module.ts 中导入了 FormsModule:

import {FormsModule} from '@angular/forms';
Run Code Online (Sandbox Code Playgroud)

...

imports: [...
FormsModule,
Run Code Online (Sandbox Code Playgroud)

我还在 component.ts 中添加了 FormsModule:

import {FormsModule} from '@angular/forms';
Run Code Online (Sandbox Code Playgroud)

我需要从“@angular/material”获得什么?

Cha*_*oot 5

您可以在不使用ngModel 的情况下实现这种物质方式

isChecked = true;

<md-checkbox
          class="example-margin"
          [checked]="isChecked"
          [indeterminate]="indeterminate"
          [align]="align"
          (change)="isChecked = !isChecked"
          [disabled]="disabled">
        I'm a checkbox
      </md-checkbox>
Run Code Online (Sandbox Code Playgroud)

plunker https://plnkr.co/edit/xCpLFKzQnur9Si2KECiW?p=preview