我正在运行来自here的单选按钮的示例,我确保关注所有instruction,除了附录,因为我没有 这样的文件(我的应用程序是创建cli)。
在包含html模板后,我的应用程序无法渲染,在控制台中我出错了:
无法绑定'值'因为它不是一个已知的属性 ' MD-单选按钮
我的ts档案:
import { Component, OnInit } from '@angular/core';
import { SlidesService } from 'app/slides/slides.service';
import { Slide } from 'app/slides/slide';
import { Observable } from 'rxjs/Rx';
import { Subscription } from 'rxjs/Subscription';
import { MdButtonModule, MdCheckboxModule } from '@angular/material';
@Component({
selector: 'app-question',
templateUrl: './question.component.html',
styleUrls: ['./question.component.css']
})
export class QuestionComponent implements OnInit {
constructor(private _slidesService: SlidesService) { }
slides: Slide[];
currSlide: Slide;
favoriteSeason: string;
seasons = [
'Winter',
'Spring',
'Summer',
'Autumn',
];
ngOnInit() {
this._slidesService.getSlides()
.subscribe(slides => {
this.slides = slides
this.currSlide = slides[0];
},
error => console.log(<any>error));
}
}
我的html文件:
<div class="well well-lg" *ngIf='slides && slides.length'>
<img [src]='slides[0].imageUrl'>
<h1>{{currSlide.SongTitle}}</h1>
<md-radio-group class="example-radio-group" [(ngModel)]="favoriteSeason">
<md-radio-button class="example-radio-button" *ngFor="let season of seasons" [value]="season">
{{season}}
</md-radio-button>
</md-radio-group>
<div class="example-selected-value">Your favorite season is: {{favoriteSeason}}</div>
</div>
的AppModule:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AlertModule } from 'ngx-bootstrap';
import { CarouselModule } from 'ngx-bootstrap/carousel';
import { AppComponent } from './app.component';
import { SlidesComponent } from './slides/slides.component';
import { SlidesService } from './slides/slides.service';
import { QuestionComponent } from './question/question.component';
import { MdButtonModule, MdCheckboxModule } from '@angular/material';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormControl, FormGroup } from '@angular/forms';
import { MaterialModule } from '@angular/material';
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
SlidesComponent,
QuestionComponent
],
imports: [ReactiveFormsModule, MaterialModule,
BrowserAnimationsModule,
MdButtonModule,
MdCheckboxModule,
BrowserModule,
FormsModule,
HttpModule,
AlertModule.forRoot(),
CarouselModule.forRoot()
],
providers: [SlidesService],
bootstrap: [AppComponent]
})
export class AppModule { }
我很欣赏解决此问题的建议。
答案 0 :(得分:4)
由于这似乎没有得出结论,我想我会提供答案,所有将归功于Neil Lunn!
由于Sajeetharan的答案适用于导入的MaterialModule
,但正如Neil Lunn所说:
您只应导入“必需”模块
因为否则
这将导致更大的构建包。
因此,只需将MdRadioModule
导入您的应用模块并将其添加到imports
数组即可解决此问题:
import { MdRadioModule } from '@angular/material';
imports: [
....
MdRadioModule,
....
],
答案 1 :(得分:2)
您必须在appModule中导入PropertyChanged
,并将其粘贴到YourValueProperty
下。