gpt4 book ai didi

javascript - ng-options 指令不起作用,无法在 angularjs 库中找到它

转载 作者:行者123 更新时间:2023-12-03 09:17:37 24 4
gpt4 key购买 nike

我的 ng-option 指令不起作用,在 AngularJS 库中找不到它。我尝试了几乎所有有效的来源,但仍然只有这个指令不起作用。即使我尝试了 angularjs.org 网站上的代码。

<html>
<head>
<title>View</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>

<script>
var mymodule = angular.module('mymodule' ,[]);
mymodule.controller('x' , function($scope){
$scope.point = ['point1' , 'point2' , 'point3' , 'point4'];
$scope.selectedpoint = $scope.point[1];
});
</script>
</head>
<body ng-app="mymodule">
<div ng-controller="x">
<select ng-model="selectedpoint" ng-options="item from items in point"></select>
Select = {{selectedpoint}}
<hr/>
<div ng-switch="selectedpoint">
<div style="border: 1px solid;" ng-switch-when="point1"> First file is selected</div>
<div style="border: 1px solid;" ng-switch-when="point2"> Second file is selected</div>
<div style="border: 1px solid;" ng-switch-when="point3"> Third file is selected</div>
<div style="border: 1px solid;" ng-switch-when="point4"> Fourth file is selected</div>
</div>
</div>
</body>

最佳答案

正确的语法是:

 <select ng-model="selectedpoint" ng-options="item as item for item in point"></select>

对于:

<option value="point1">point1</option>
<option value="point2">point2</option>
<option value="point3">point3</option>

或者:

 <select ng-model="selectedpoint" ng-options="item for item in point"></select>

对于:

<option value="0">point1</option>
<option value="1">point2</option>
<option value="2">point3</option>

关于javascript - ng-options 指令不起作用,无法在 angularjs 库中找到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31918595/

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