gpt4 book ai didi

Angular 4。错误 "Can' t 绑定(bind)到 'ngModule',因为它不是“的已知属性”,但 FormsModule 是在 app.module.shared.ts 中导入的

转载 作者:搜寻专家 更新时间:2023-10-30 21:19:44 26 4
gpt4 key购买 nike

我被困住了“无法绑定(bind)到‘ngModule’,因为它不是‘select’的已知属性。”错误。该解决方案应该是在 app.module.shared.ts 文件中导入 FormsModule。我做了,但我仍然遇到同样的错误。

app.module.shared.t

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './components/app/app.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { StatisticComponent} from './components/statistic/statistic.component';
import { StatisticViewComponent } from './components/statisticview/statisticview.component';
import { StatService } from './components/services/stat.service';


@NgModule({
declarations: [
AppComponent,
NavMenuComponent,
HomeComponent,
StatisticComponent,
StatisticViewComponent
],
imports: [
FormsModule,
CommonModule,
HttpModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'statistic', component: StatisticComponent },
{ path: 'statisticview', component: StatisticViewComponent },
{ path: '**', redirectTo: 'home' }
])
],
providers: [
StatService
]
})
export class AppModuleShared {
}

statisticview.component.ts

import { StatService } from './../services/stat.service';
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-statistic-view',
templateUrl: './statisticview.component.html',
styleUrls: ['./statisticview.component.css']
})
export class StatisticViewComponent implements OnInit {
private affiliates:string[]
selectedAffiliate: any;

constructor(private statService: StatService) {
}

ngOnInit(): void {
this.statService.getAvailableAffiliates().subscribe( s => {
this.affiliates = s;
console.log(s);
})
}

OnAffiliateChange() {
console.log(this.selectedAffiliate)
}

}

statisticview.component.html

<div class="row">
<div class="form-group">
<label for="aff">Affiliate</label>
<select name="aff" id="aff" class="form-control" (change)="OnAffiliateChange()" [(ngModule)] ="selectedAffiliate">
<option value=""></option>
<option *ngFor="let a of affiliates" value="{{a}}">{{a}}</option>
</select>
</div>
</div>

来自 package.json

 "dependencies": {
"@angular/animations": "4.2.5",
"@angular/common": "4.2.5",
"@angular/compiler": "4.2.5",
"@angular/compiler-cli": "4.2.5",
"@angular/core": "4.2.5",
"@angular/forms": "4.2.5",
"@angular/http": "4.2.5",
"@angular/platform-browser": "4.2.5",
........

最佳答案

应该是 ngModel 而不是 NgModule

  <select name="aff" id="aff" class="form-control" (change)="OnAffiliateChange()" [(ngModel)] ="selectedAffiliate">
<option value=""></option>
<option *ngFor="let a of affiliates" value="{{a}}">{{a}}</option>
</select>

关于Angular 4。错误 "Can' t 绑定(bind)到 'ngModule',因为它不是“的已知属性”,但 FormsModule 是在 app.module.shared.ts 中导入的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46426206/

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