gpt4 book ai didi

javascript - Angular 2 : Toggle buttons are not working as expected

转载 作者:行者123 更新时间:2023-11-28 04:57:31 25 4
gpt4 key购买 nike

我正在尝试在 md-list 中显示 Material 2 切换按钮。不知道为什么它们显示为单选按钮。

<md-list>
<md-button-toggle-group #group="mdButtonToggleGroup">
<md-list-item><md-button-toggle>First Button</md-button-toggle></md-list-item>
<md-list-item><md-button-toggle>Second Button</md-button-toggle></md-list-item>
</md-button-toggle-group>
</md-list>

enter image description here

app.module.ts

import {MaterialModule} from "@angular/material";
import 'hammerjs';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
CommonModule,
FormsModule,
HttpModule,
MaterialModule
],
providers: [__platform_browser_private__.BROWSER_SANITIZATION_PROVIDERS],
bootstrap: [AppComponent]
})
export class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);

依赖关系

"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/material": "^2.0.0-beta.2",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/hammerjs": "^2.0.34",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.24",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.0.2",
"typescript": "~2.0.3"
}

最佳答案

鉴于它在 plunker 中有效:http://plnkr.co/edit/AiqtVcMFo8ShzLe18ArU?p=preview

我建议检查此列表:

  1. 始终首先检查版本(可能是某些旧版本中的错误)
  2. 我不是 100% 确定您可以将 md-list 子标签与 md-button-toggle-group 子标签混合使用...来检查来源(由 plunker 提供)。潜在的问题是您嵌套的标签呈锯齿状...

正常:

<md-list>
<md-list-item>
</md-list-item>
</md-list>

<md-button-toggle-group>
<md-button-toggle>
</md-button-toggle>
</md-button-toggle-group>

但是你有:

<md-list>
<md-button-toggle-group>
<md-list-item>
<md-button-toggle>
</md-button-toggle>
</md-list-item>
</md-button-toggle-group>
</md-list>
  • css 样式和代码 angular2 指令是如何编译的,没有人知道压倒一切的风格。有时,样式可以使用/deep/(或 >>>)修饰符遍历所有代码。

  • 在 AppModule 中使用 MaterialModule.forRoot()

  • 关于javascript - Angular 2 : Toggle buttons are not working as expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42419997/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com