我的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>
最佳答案
我已经修改了代码,您使用的是“ from”而不是“ for”
Correct Verion of Code in Plunker
<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 for item 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>
</html>