ng-select中的把手角度JS解析错误

时间:2015-10-10 03:59:46

标签: javascript angularjs

我有一个ng-repeat div,div里面有select控件。此代码生成解析错误:

<select name="qty" ng-model="Qty">
   <option ng-repeat="v in [1,2,3,4,5,6,7,8,9,10]" 
           value="{{v}}" ng-selected="v=={{item["menuItem.Qty"]}}">
           {{v}}        
   </option>
</select>

F12 控制台中,它会打印ng-selected="{{item[" menuitem.qty"]}}"=""

所以,我看到把手和阵列存在问题,但是无法弄清楚这里到底出了什么问题。

2 个答案:

答案 0 :(得分:0)

更改

ng-selected="v=={{item["menuItem.Qty"]}}"

ng-selected="v=={{item['menuItem.Qty']}}"

答案 1 :(得分:0)

这是一个解决方案:

&#13;
&#13;
(function() {
  'use strict';

  angular.module('App', [])
    .controller('InputCtrl',['$scope', function($scope){
    $scope.menuItem={};
      $scope.menuItem.Qty = 1;
      $scope.item = {};
      
    $scope.item[1] = 1;
  }]);

}());
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<div ng-app="App" ng-controller="InputCtrl">
<select name="qty" ng-model="Qty" >
   <option ng-repeat="v in  [1,2,3,4,5,6,7,8,9,10]" 
           value="{{v}}" ng-bind="v" ng-selected="v==item[menuItem.Qty]">
           
   </option>
</select>
  Qty:{{Qty}}<br/>
  item:{{item}}
  </div>
&#13;
&#13;
&#13;