gpt4 book ai didi

javascript - 从 Controller 读取 JSON 文件并使用 ng-repeat 显示为
  • 转载 作者:塔克拉玛干 更新时间:2023-11-02 23:03:02 28 4
    gpt4 key购买 nike

    我的 employee.json 文件与我的 Controller 位于同一目录中。

    这是我的 json 文件中的数据:

    ["John", "Clark"]

    在我的 Controller 上:

    .controller('EmployeeCtrl', function ($scope, $http) {
    $http.get('employee.json').then(function (res) {
    $scope.contents = res.data;
    });
    });

    在我的模板上:

    <div>
    <label class="control-label">Identify yourself:</label>
    <select ng-model="market.name">
    <option ng-repeat="content in contents" value="{{content}}">{{content}} </option>
    </select>
    </div>

    有谁知道为什么这不起作用?我的下拉列表不显示任何内容。

    最佳答案

    .controller('EmployeeCtrl', function ($scope, $http) {
    $http.get('employee.json').success(function (res) {
    $scope.contents = response.data;
    });
    });

    还要确保 JSON 文件中的数据格式正确。

    关于javascript - 从 Controller 读取 JSON 文件并使用 ng-repeat 显示为 <li>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31817612/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com