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

标签 javascript html angularjs

我的 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/

相关文章:

javascript - Laravel 使用 JavaScript 重定向

html - .less 文件无法正确加载

html - 当 <a> 标签包含图片 URL 时如何设置 alt 属性?

javascript - 我如何修改 Angular 图表js中的刻度标签?

javascript - 是否有任何理由在 HTML 中转义整数?

javascript - 可以强制 chrome 按存储顺序迭代 "string numeric"键

php - 无法打印从 javascript 传递到 php 的数组

javascript - 如何使滚动更平滑(不是 anchor 链接,只是一般滚动)

javascript - Angular RouteParams 返回一个空对象

javascript - Angular API 引用代码