javascript - 如何将 ng-options 更改为 ng-repeat?

标签 javascript angularjs

我是 AngularJS 初学者开发人员,我正在构建简单的应用程序,但我遇到了问题

这是我的 HTML

<div ng-app="MyApp">
  <div ng-controller="TabsDemoCtrl">
    <div ng-controller="TabsDemoCtrl">      
      <label>Category</label>
      <select class="form-control" ng-model="product.category" ng-options="category as category.name for category in categories"></select>    
    </div>

    <label>how to change ng-options to be ng-repeat ?my achieve is to be like this</label>
    <input type="text" class="form-control" value="custom">
    <input type="text" class="form-control" value="non-custom">
  </div>
</div>

这是我的 Js

angular.module('MyApp', [
    'ui.bootstrap']);

(function(MyApp) {
  'use strict';
  MyApp.controller('TabsDemoCtrl', ['$scope', function($scope) {
    // categories
    $scope.categories = [
      {
        name:'custom', 
        templateAttribute: [
          {attribute: 'material'},
          {attribute: 'soles'},
          {attribute: 'size'}
        ]
      },
      {
        name:'non-custom', 
        templateAttribute: [
          {attribute: 'material'},
          {attribute: 'soles'},
          {attribute: 'size'}
        ]
      }
    ];     
  }]);
})(angular.module('MyApp'));

这是我的简单demo

如何将ng-option上的数据输出为重复表单文本?提前致谢

最佳答案

我也是 Angular 的新手,但这在过去几天对我很有用。

<div ng-controller="TabsDemoCtrl">      
    <label>Category</label>
    <select class="form-control" > 
        <option ng-repeat="category in categories">{{category.name}}</option> 
    </select>    
</div>

关于javascript - 如何将 ng-options 更改为 ng-repeat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34647435/

相关文章:

javascript - 从点计算可能的线

html - Angular - ng 类在 td 上工作但不在 tr 上工作

javascript - 如何在 AngularJS Controller 中使用环境变量?

javascript - 从 Controller 访问 templateUrl 内的元素 - AngularJS

javascript - 正在更新 `ObservableArray` json 格式的项目

javascript - 为什么我不能渲染这个 angularJS 代码?

javascript - IIFE 引发错误

javascript - React Relay (react-relay) 与 Typescript 抛出 TypeError : Object prototype may only be an Object or null: undefined

javascript - JS/jQuery > 在附加输入中突出显示文本

javascript - jQuery Animate 宽度卡住 iPad