【问题标题】:md-toggle-button not toggling in angularmd-toggle-button 不切换角度
【发布时间】:2017-12-05 13:39:08
【问题描述】:

我需要显示一些切换按钮,这些按钮出现在 angular material https://material.angular.io/components/button-toggle/overview 的文档页面中。我跟着代码,都试过了

<md-button-toggle ng-click="vm.callAlert()">Hello</md-button-toggle>

<mat-button-toggle ng-click="vm.callAlert()">Hello</mat-button-toggle>

然后调用函数。问题是按钮没有保持焦点。有人可以帮我吗?

【问题讨论】:

  • 看看你的代码中是否调用了“关闭”函数,或者是否多次调用了“切换”函数
  • 顺便说一下,您引用的文档站点不是针对 AngularJS 1.x,而是针对 Angular 2、4 和 5!!

标签: javascript angular angular-material angular-material2


【解决方案1】:

首先,请不要在您的模板中使用ng-click。请改用(click) 事件。有关更多信息,请访问 documentation 了解模板语法。

其次,注意 Angular 不再使用控制器语法。

第三,在应用的模块文件中从@angular/material 导入MatButtonToggleModule

将您的代码更新为以下内容:

HTML 代码 (app.component.html):

<mat-button-toggle (click)="clickActn()">Toggle me!</mat-button-toggle>

组件代码(app.component.ts):

@Component({
    selector: 'app-root',
    templateUrl: 'app.component.html'
})
export class AppComponent {
    clickActn() {
        console.log('clicked');
    }
}

【讨论】:

    猜你喜欢
    • 2017-08-23
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    相关资源
    最近更新 更多