gpt4 book ai didi

angularjs - 带有对象数据源的 ng-options

转载 作者:行者123 更新时间:2023-12-03 05:56:06 25 4
gpt4 key购买 nike

我正在努力理解 ng-options 如何处理数据源。我已经阅读了文档,我觉得我正在按照要求做,但在尝试时仍然遇到问题。

<!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'.

我做错了什么?

请参阅此处:

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

最佳答案

这有点奇怪,但似乎你需要在for后面加一个空格。这有效:

<select ng-model="type" ng-options="k as v for (k, v) in types">
<option value="">Select Type</option>
</select>

关于angularjs - 带有对象数据源的 ng-options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20392678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com