![](/img/trans.png)
[英]select ng-options not updating ng-model in AngularJS with ajax
[英](AngularJS) ng-options not populating despite ng-model and previously working syntax
解決 :兩部分問題。 正如Veera指出的那樣,模型未正確存儲在控制器中,主要問題與模塊聲明中的Smart Table注入有關。
以前,我下面的代碼設法從ng-options的下拉菜單中生成列表。 在進行了幾項看似無關的更改之后,它現在不起作用了,我無法一生找出原因。
我知道很多人在select元素中都有ng-model的問題,因此除非我犯了一個錯誤並錯過了一些語法,否則我認為這不是問題,因為它正在起作用。
我正在嘗試使用控制器中的數組中的“引用號”填充列表。 在變量名稱和數據中可能存在一些錯別字,而我在實際項目中使用的錯別字。
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>
感謝您抽出寶貴的時間仔細閱讀它。 康納
將ng-model更改為對象並在控制器中聲明
HTML
<select ng-model="selected.selectedReference"
ng-options="request.ref for request in requests">
<option value=""></option>
</select>
JS
$scope.selected = {};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.