(AngularJS)ng-options尽管有ng-model和以前的工作语法,但不会填充

时间:2017-07-03 13:44:02

标签: javascript angularjs web-applications

解决:两部分问题。正如Veera所指出的那样,模型没有正确存储在控制器中,主要问题与模块声明中的智能表注入有关。

以前我的代码设法从ng-options的下拉菜单中生成一个列表。经过几次看似无关的改变后,它现在无法正常工作,我无法为我的生活找出原因。

我理解很多人在select元素中都存在ng-model的问题,所以除非我犯了错误并错过了一些语法,否则我认为这不是问题,因为它正在工作。

我正在尝试使用" Ref Number"填充列表。从控制器中的数组。可变名称和数据中可能存在一些拼写错误,我将其与我在实际项目中使用的名称和数据进行了更改。



var reqWebApp = angular.module('reqWebApp', ['smart-table']);

    reqWebApp.controller('reqAppController', function reqAppController($scope) {
        $scope.requests = [
           {
                ref : "000455",
                status : "requested",
                prod : "BLEH",
                prodRef : "NAH8754",
                prodSite : "BLEHTON"
            }
            {
                ref : "003005",
                status : "requested",
                prod : "REDACTED",
                prodRef : "NA78546",
                prodSite : "REDVILLE"
            }
        ];
});

<!DOCTYPE html>
<html lang="en" ng-app="reqWebbApp">
<head>
    <meta charset="UTF-8">
    <title>Pre-Acceptance</title>
    <script src="../../bower_components/angular/angular.js"></script>
    <script src="../../app.js"></script>
    <style>
        table { width: 90%; }
        input { width: 95%; }
        select { width: 100%; }
    </style>
</head>

<body ng-controller="reqAppController">
    <div style="display:inline">Pre-Accept Existing Request |
        <table style="display:inline-table; width: 5%" border="1" >
            <tr>
                <th>
                    Ref No.
                </th>
            </tr>
            <tr>
                <th>
                    <select ng-model="references"
                            ng-options="request.ref for request in requests">
                        <option value=""></option>
                    </select>
                </th>
            </tr>
        </table>
    </div>
    <button type="button" onclick="location.href='../home/homepage.html'">ACCEPT</button>
    <button type="button" onclick="location.href='../home/homepage.html'">HOME</button>
</body>
</html>
&#13;
&#13;
&#13;

感谢任何人有时间浏览它。 康纳

1 个答案:

答案 0 :(得分:0)

将ng-model更改为对象并在控制器中声明

HTML

 <select ng-model="selected.selectedReference"
  ng-options="request.ref for request in requests">
   <option value=""></option>
 </select>

JS

 $scope.selected = {};
相关问题