angularjs – ng选项与对象数据源

前端之家收集整理的这篇文章主要介绍了angularjs – ng选项与对象数据源前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我很难理解ng选项如何工作与数据源。我读过文档,我觉得我做的正是所需要的,但我仍然遇到问题时尝试。
<!DOCTYPE html>
<html ng-app="app">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js">              </script>
    <link rel="stylesheet" href="style.css" />
    <script type="text/javascript">
      angular.module('app',[])
      .controller('IndexCtrl',['$scope',function($scope) {
        $scope.types = {
          1: "value1",2: "value2",5: "value3"
        };
      }]);
    </script>
  </head>
  <body ng-controller="IndexCtrl">
    <select ng-model="type" ng-options="k as v for(k,v) in types">
      <option value="">Select Type</option>
    </select>
  </body>
</html>

我总是在控制台中得到这个错误

错误

Expected ngOptions in form of ‘select (as label)? for (key,)?value in collection (track by expr)?’ but got ‘k as v for(k,v) in types’.

我做错了什么?

请参见plunkr:

http://plnkr.co/edit/Bl6u4151KyDkxhYrsdCm?p=preview

这是一种奇怪,但它似乎你需要放一个空间后。这工作:
<select ng-model="type" ng-options="k as v for (k,v) in types">
  <option value="">Select Type</option>
</select>
原文链接:https://www.f2er.com/angularjs/146371.html

猜你在找的Angularjs相关文章