【问题标题】:select tag of angularjs选择angularjs的标签
【发布时间】:2015-09-24 17:42:11
【问题描述】:

我尝试在 angularJS 中填写一个选择,但它不起作用,我不明白为什么。 因此,在我的控制器中,我使用 http 请求来填充历史对象的 cShops 属性。我在我的属性上使用 Console.Dir() 来显示内容,并且我的变量很好地填充。所以我尝试使用这个对象列表来填充我的选择标签,但它不起作用,我在 chrome 控制台中没有错误。

使用包含商店列表的属性获取 Historic 的方法:

var reqGetHistEmployees = $http({ url: 'api/Employees/GetHistoryEmployee', params: { 'id': id } });
                reqGetHistEmployees.success(function (resolve) {
                    $scope.histEmployee = resolve;
                    console.log('histEmployee[0].cShops : ');
                    console.dir($scope.histEmployee[0].cShops);
                });

所以当我验证清单时,商店已经满了。所以我试图在我的 html 中的一个选择中显示这个列表:

Affectations :
        <table class="myTable">
            <thead style="background-color:#54a0fc !important;">
                <tr>
                    <th>{{'Shop' | i18n}}</th>
                    <th>{{'Function' | i18n}}</th>
                    <th>{{'Contract' | i18n}}</th>
                    <th>{{'Entrance' | i18n}}</th>
                    <th>{{'Ending' | i18n}}</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="hist in histEmployee">
                    <td><select ng-options="shop.Name for shop in hist.cShops track by shop.ShopID"></select></td>
                    <td>{{hist.FunctionName}}</td>
                    <td>{{hist.ContractName}}</td>
                    <td>{{hist.DateOfEntry | date:'shortDate'}}</td>
                    <td>{{hist.DateOfEnding | date:'shortDate'}}</td>
                </tr>
            </tbody>
        </table>

但我的选择是空的,我在控制台上没有错误,所以我不知道如何解决这个问题。

提前感谢您能给我的任何帮助

【问题讨论】:

    标签: html angularjs select


    【解决方案1】:

    您的选择标签中缺少 ng-model 属性。

    https://docs.angularjs.org/api/ng/directive/ngOptions。如果我的提示不能解决您的问题,您可能会遗漏其他内容。阅读文档 - 这应该是您自己做的简单修复。

    更新
    我猜您还想在选择时存储商店 ID,并希望为用户显示名称。

    所以你需要这样做: 选择作为数组

    标签

    您的选择:id
    您的标签:姓名
    您的价值:商店
    你的数组: hist.cShops

    【讨论】:

    • 谢谢,我不知道选择的第二种形式,它可以工作。