【问题标题】:Using ng-repeat over nested javascript objects to display select-options在嵌套的 javascript 对象上使用 ng-repeat 来显示选择选项
【发布时间】:2014-01-10 02:21:15
【问题描述】:

如何使用 Angular 的 ng-repeat 指令显示两个带有正确选项的下拉菜单?

这是JSBin

js:

 angular.module('myApp', [])
    .controller('MainCtrl', function($scope) {

      $scope.templates = {
        pages: ['home', 'about'],
        posts: ['blog', 'lab']

      };

    });

HTML:

 <div class="container" ng-controller="MainCtrl">
    <form action="" class="col-lg-12" >
       <select class="form-control" ng-repeat="template in templates.pages>
        <option value = "{{ template }}"> {{ template }}</option>
      </select>
      <select class="form-control" ng-repeat="template in templates.posts>
        <option value = "{{ template }}"> {{ template }}</option>
      </select> 
    </form>

  </div>

【问题讨论】:

    标签: javascript html angularjs angularjs-ng-repeat 2-way-object-databinding


    【解决方案1】:

    ng-repeat 应该用在选项标签中。此外,在您的 ng-repeat 表达式中关闭双引号。

    这里是你的固定JSBin

    【讨论】:

      猜你喜欢
      • 2016-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多