响应数据未使用ng-repeat绑定到表

用户名

我正在使用angularJS开发示例应用程序。

我有一个返回JSON对象的服务,我正在尝试将响应绑定到表。

控制器 -

(function () {
    var app = angular.module('searchApp', []);
    app.config(function ($sceDelegateProvider) {
        $sceDelegateProvider.resourceUrlWhitelist(['http://localhost:11838/SearchProfiles/get']);
    });
    var controller = app.controller('searchController', ["$scope", "$http", function ($scope, $http) {
        $scope.profileName = "";
        $http.get("http://localhost:11838/SearchProfiles/GetAllRuleSets")
            .then(function (response) {
                $scope.ruleSets = response.data;
        });
        $scope.searchProfiles = function () {
            $http.get("http://localhost:11838/SearchProfiles/GetProfiles?profileName=" + $scope.profileName
                + "&ruleSetName=" + $scope.selectedRuleSet)
            .then(function (response) {
                $scope.showProfiles = true;
                $scope.profiles = response.data;
                console.log($scope.profiles);
            });
        };
        $scope.clearForm = function () {
            $scope.profileName = "";
            $scope.selectedRuleSet = "";
        };
    }]);
})();

cshtml-

@{
    ViewBag.Title = "Search Profiles";
}
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Search Profiles</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
    @Scripts.Render("~/Scripts/angular")
    @Styles.Render("~/Content/css/scss")
</head>
<body ng-app="searchApp">
    <div ng-controller="searchController" id="content">
        <label>Profile Name: </label>
        <input type="text" name="profileName" ng-model="profileName" /><br />
        <label>RuleSet Name: </label>
        <select ng-model="selectedRuleSet" ng-options="x for x in ruleSets"></select><br />
        <button name="search" ng-click="searchProfiles()">Search</button>
        <button name="clear" ng-click="clearForm()">Clear</button>
    </div>
    <div ng-controller="searchController" id="profilesDiv">
        <table>
            <tr ng-repeat="x in profiles">
                <td>{{ x.ProfileName }}</td>
                <td>{{ x.CreationDate }}</td>
            </tr>
        </table>
    </div>
</body>

我在回应后回来了-

[{"ProfileName":"Profile3","CreationDate":"1/9/2017"},{"ProfileName":"Profile4","CreationDate":"12/30/2016"}]

但即使设置后,$scope.profiles我也没有在UI上看到表格。

我对棱角还很陌生,我是否缺少明显的东西。任何帮助表示赞赏。

马库斯·霍格隆德(MarcusHöglund)

问题是您要在一个作用域(声明ng-controller =“ searchController”的div内容)中获取数据,然后尝试在另一个作用域(divprofilesDiv中再次声明ng-controller =的视图中)查看数据。“ searchController”)。

要解决此问题,您需要从profilesDiv中删除ng-controller =“ searchController”并将profilesDiv移到内容div中。

像这样:

 <body ng-app="searchApp">
        <div ng-controller="searchController" id="content">
            <label>Profile Name: </label>
            <input type="text" name="profileName" ng-model="profileName" /><br />
            <label>RuleSet Name: </label>
            <select ng-model="selectedRuleSet" ng-options="x for x in ruleSets"></select><br />
            <button name="search" ng-click="searchProfiles()">Search</button>
            <button name="clear" ng-click="clearForm()">Clear</button>
          <div id="profilesDiv">
            <table>
                <tr ng-repeat="x in profiles">
                    <td>{{ x.ProfileName }}</td>
                    <td>{{ x.CreationDate }}</td>
                </tr>
            </table>
        </div>
        </div>

    </body

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

JSON响应未绑定到jQuery数据表

来自分类Dev

JSON响应未绑定到jQuery数据表

来自分类Dev

angularjs对象列表未绑定到ng-repeat

来自分类Dev

angularjs对象列表未绑定到ng-repeat

来自分类Dev

将ng-repeat绑定到诺言

来自分类Dev

使用ng-repeat进行数据绑定后如何更改表结构

来自分类Dev

如何使用 AngularJS 的 ng-repeat 绑定从 Dataset 转换为 HTML 表的 JSON 数据?

来自分类Dev

图表数据绑定到数据表-图表未更新

来自分类Dev

AngularJS范围未绑定ng-repeat中的数据

来自分类Dev

将嵌套的ng-repeat绑定到模型

来自分类Dev

将Angular ng-repeat绑定到WebSQL / SQLLite

来自分类Dev

Angular $ scope.model不会绑定到ng-repeat

来自分类Dev

角度ng-repeat绑定到array中的对象数组

来自分类Dev

Angular $ scope.model不会绑定到ng-repeat

来自分类Dev

ng-repeat 不绑定到列表项

来自分类Dev

未显示绑定到ng-grid的数据

来自分类Dev

如何在ng-repeat中使用ng-init将值绑定到变量?

来自分类Dev

如何在ng-repeat中使用ng-init将值绑定到变量?

来自分类Dev

将$ http.get()请求中的数据绑定到ng-repeat中

来自分类Dev

AngularJS:使用jQuery将事件侦听器绑定到ng-repeat生成的元素

来自分类Dev

如何使用ng-repeat迭代相同的值并将其绑定到ul

来自分类Dev

jQuery ajax响应绑定到MVC模型表

来自分类Dev

如何将Json响应绑定到表

来自分类Dev

如何在数据列表选择的选项ng-repeat中将对象绑定到ng-model

来自分类Dev

表格是数据绑定到ng-repeat内的ng模型...但是所有重复的值都被更改了吗?

来自分类Dev

将记录从数据集或数据表绑定到标签

来自分类Dev

无法将数据绑定到角度材料数据表

来自分类Dev

将动态创建的控件绑定到数据表的数据

来自分类Dev

ng-repeat中的数据绑定范围

Related 相关文章

  1. 1

    JSON响应未绑定到jQuery数据表

  2. 2

    JSON响应未绑定到jQuery数据表

  3. 3

    angularjs对象列表未绑定到ng-repeat

  4. 4

    angularjs对象列表未绑定到ng-repeat

  5. 5

    将ng-repeat绑定到诺言

  6. 6

    使用ng-repeat进行数据绑定后如何更改表结构

  7. 7

    如何使用 AngularJS 的 ng-repeat 绑定从 Dataset 转换为 HTML 表的 JSON 数据?

  8. 8

    图表数据绑定到数据表-图表未更新

  9. 9

    AngularJS范围未绑定ng-repeat中的数据

  10. 10

    将嵌套的ng-repeat绑定到模型

  11. 11

    将Angular ng-repeat绑定到WebSQL / SQLLite

  12. 12

    Angular $ scope.model不会绑定到ng-repeat

  13. 13

    角度ng-repeat绑定到array中的对象数组

  14. 14

    Angular $ scope.model不会绑定到ng-repeat

  15. 15

    ng-repeat 不绑定到列表项

  16. 16

    未显示绑定到ng-grid的数据

  17. 17

    如何在ng-repeat中使用ng-init将值绑定到变量?

  18. 18

    如何在ng-repeat中使用ng-init将值绑定到变量?

  19. 19

    将$ http.get()请求中的数据绑定到ng-repeat中

  20. 20

    AngularJS:使用jQuery将事件侦听器绑定到ng-repeat生成的元素

  21. 21

    如何使用ng-repeat迭代相同的值并将其绑定到ul

  22. 22

    jQuery ajax响应绑定到MVC模型表

  23. 23

    如何将Json响应绑定到表

  24. 24

    如何在数据列表选择的选项ng-repeat中将对象绑定到ng-model

  25. 25

    表格是数据绑定到ng-repeat内的ng模型...但是所有重复的值都被更改了吗?

  26. 26

    将记录从数据集或数据表绑定到标签

  27. 27

    无法将数据绑定到角度材料数据表

  28. 28

    将动态创建的控件绑定到数据表的数据

  29. 29

    ng-repeat中的数据绑定范围

热门标签

归档