【问题标题】:AngularJS dropdown select not workingAngularJS下拉选择不起作用
【发布时间】:2015-10-28 20:12:27
【问题描述】:

我正在使用 Angular 编写一个下拉选择菜单,其中包含一些提交到数据库的选项。在前端html中:

Role Type: 
<select ng-model = "Role_Type">
    <option ng-repeat="role in roles" value="{{role}}"> {{role}} </option>
</select>

在我的控制器中,我有:

$scope.roles = ['Teacher', 'Student', 'Janitor', 'Principal'];
$scope.addNewEntry = function() {
      entrys.addNewEntry({
         Role_Type: $scope.role,
      });
}

在我的后端(使用 Mongoose.js)架构中,我有:

var EntrySchema = new mongoose.Schema({
      Role_Type: String,
});

我使用下面的代码在前端显示回来:

Role Type:
{{entry.Role_Type}}

但这不起作用。前端没有显示任何内容。有什么想法吗?

【问题讨论】:

    标签: angularjs mongoose angularjs-ng-repeat schema mean-stack


    【解决方案1】:

    不要使用ng-repeat,而是尝试使用ng-options,它用于在下拉菜单中重复值。

    <select ng-model="Role_Type" ng-options="role for role in roles"></select>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多