Javascript 角度6:TypeError:无法读取属性';价值';未定义的

Javascript 角度6:TypeError:无法读取属性';价值';未定义的,javascript,angular,html,twitter-bootstrap,typescript,Javascript,Angular,Html,Twitter Bootstrap,Typescript,我正在创建一个简单的表单来提交数据、电子邮件、城市名称和酒店名称,当我单击“提交”时,我收到以下错误: AboutComponent.html:79错误类型错误:无法读取属性“value” 未定义的 以下是我所拥有的: comment.js // Comments Schema const CommentsSchema = mongoose.Schema({ email: { type: String, required: true }, name: {

我正在创建一个简单的表单来提交数据、电子邮件、城市名称和酒店名称,当我单击“提交”时,我收到以下错误:

AboutComponent.html:79错误类型错误:无法读取属性“value” 未定义的

以下是我所拥有的: comment.js

// Comments Schema

const CommentsSchema = mongoose.Schema({

  email: {
    type: String,
    required: true
  },
  name: {
    type: String,
    required: true
  }
},{
    collection: 'comments'
});

const Comments = module.exports = mongoose.model('Comments', CommentsSchema);
组件技术

addReview(email, name) {
    this.moviesService.addReview(email, name).subscribe(success => {
      this.flashMessages.show('You are data we succesfully submitted', { cssClass: 'alert-success', timeout: 3000 });
      // get the id
      this.activeRouter.params.subscribe((params) => {
        // tslint:disable-next-line:prefer-const
        let id = params['id'];
        this.moviesService.getComments(id)
          .subscribe(comments => {
            console.log(comments);
            this.comments = comments;
          });
      });
    }, error => {
      this.flashMessages.show('Something went wrong', { cssClass: 'alert-danger', timeout: 3000 });
    });
  }
html


电子邮件是必需的。
{{city.name}
{{hotel.name}
加入者
服务台

 addReview(email, name): Observable<any> {
    const uri = `${apiUrl + this.addCommentsUrl}`;
    const obj = {
      email: email,
      name: name
    };
    return this.http.post(uri, obj);
  }
addReview(电子邮件,姓名):可观察{
常量uri=`${APIRL+this.addCommentsUrl}`;
常量对象={
电邮:电邮,,
姓名:姓名
};
返回this.http.post(uri,obj);
}
注意:当我删除姓名时,一切正常,但我还需要将城市名称和酒店名称与电子邮件一起插入我的数据库


我的代码出了什么问题?

我认为templateRef var应该在select元素上,而不是option元素上

而是这个

<option selected *ngFor="let city of cities" [ngValue]="city.name" #name>{{city.name}}</option>
{{city.name}
你能试试这个吗

<select class="custom-select" id="inputGroupSelect01">

另请注意,templateRef变量名称对于每个select元素都应该是唯一的。不能对两个不同的元素使用相同的变量

请参见此处的#名称:

1. <option selected *ngFor="let city of cities" [ngValue]="city.name" #name>{{city.name}}</option>

2. <option selected *ngFor="let hotel of hotels" [ngValue]="hotel.name" #name>{{hotel.name}}</option>
1。{{city.name}
2.{{hotel.name}

如果有帮助,请告诉我

更改templateRef变量以选择后的Hii获取错误:
请求URL:http://localhost:8000/movies/comments 请求方法:POST状态代码:400错误请求这是您的API服务器对发布数据的抱怨。确保您的网页将所需数据发布到该端点。在请求期间放置两个日志语句,以查看发生了什么。如果答案对你有帮助,也请投票或接受。在调试后,我看到email=“提供的email”和name=“”;(名称为空)在断点上,那么我需要更改什么?不确定在您的情况下可能会出现什么错误。如果不看完整的代码,就不能说太多。像这样的东西怎么样?(单击)=“添加审阅(email.value,select1.value | | select2.value)”
1. <option selected *ngFor="let city of cities" [ngValue]="city.name" #name>{{city.name}}</option>

2. <option selected *ngFor="let hotel of hotels" [ngValue]="hotel.name" #name>{{hotel.name}}</option>