相关疑难解决方法(0)

使用AngularJS从选择选项中删除空白选项

我是AngularJS的新手.我搜索了很多,但它并没有解决我的问题.

我在选择框中第一次得到一个空白选项.

这是我的HTML代码

<div ng-app="MyApp1">
    <div ng-controller="MyController">
        <input type="text" ng-model="feed.name" placeholder="Name" />
        <select ng-model="feed.config">
            <option ng-repeat="template in configs">{{template.name}}</option>
        </select>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS

var MyApp=angular.module('MyApp1',[])
MyApp.controller('MyController', function($scope) {
    $scope.feed = {};

      //Configuration
      $scope.configs = [
                                 {'name': 'Config 1',
                                  'value': 'config1'},
                                 {'name': 'Config 2',
                                  'value': 'config2'},
                                 {'name': 'Config 3',
                                  'value': 'config3'}
                               ];
      //Setting first option as selected in configuration select
      $scope.feed.config = $scope.configs[0].value;
});
Run Code Online (Sandbox Code Playgroud)

但它似乎没有用.我怎样才能解决这个问题?这是JSFiddle演示

angularjs angularjs-select

76
推荐指数
5
解决办法
13万
查看次数

标签 统计

angularjs ×1

angularjs-select ×1