Javascript Angular 1.5.5基于$http调用的返回值呈现html
考虑到以下信息,我想知道最好的方法: 我有一个控制器,它使用工厂进行2次http调用Javascript Angular 1.5.5基于$http调用的返回值呈现html,javascript,html,angularjs,angularjs-1.5,Javascript,Html,Angularjs,Angularjs 1.5,考虑到以下信息,我想知道最好的方法: 我有一个控制器,它使用工厂进行2次http调用 DataFactory.getTestDisplaySections(testID).then(function (response) { $scope.testSections = JSON.parse(response.data); }); DataFactory.getTestObjectByTestID(testID).then(function (response) { $scope
DataFactory.getTestDisplaySections(testID).then(function (response) {
$scope.testSections = JSON.parse(response.data);
});
DataFactory.getTestObjectByTestID(testID).then(function (response) {
$scope.testObject = JSON.parse(response.data);
});
该调用返回两个数组。我想用嵌入其中的数组中的数据生成html。现在,我的控制器模板只包含一个空壳页面
<div class="container">
<div class="row">
<div ng-bind-html="sectionHTML"></div>
</div>
</div>
我是否应该在for循环中遍历面板数据并以这种方式为每个面板创建html
当我尝试使用{{}}
添加panelDisplayName
时,它显示为{{panelDisplayName}}
每次我必须计算角度表达式时,这会是一个问题吗?我如何解决这个问题
其次,我需要在每个面板中显示其他信息。这来自第二个http调用。每个面板都有详细信息,每个信息都是可编辑的。有人能帮我找到最好的方法吗
如果有人需要的话,我可以给出更多的解释
谢谢
第我认为您在这里询问了多个问题,因此我将尝试帮助解决前两个问题,通过数组循环构建页面,并帮助您实现
{}
数据绑定
对于面板,不要使用For循环并在控制器中构建html。你使用的是角度,角度的方式是使用。将其添加到html模板中,它将通过迭代数组来构建dom。在您的示例中:
.html
<div class="container">
<div class="row">
<!-- this is where we are iterating over the array (ng-repeat) -->
<div class="col-lg-6" ng-repeat="section in testSections">
<div class="panel panel-primary">
<!-- section is the current item being iterated in the array, so we are printing the displayName for the section -->
<div class="panel-heading lead">{{section.panelDiaplayName}}</div>
<div class="panel-body">
<div id="test_info" class="col-lg-12">
</div>
</div>
</div>
</div>
</div>
</div>
<body ng-app="yourApp" ng-controller="yourController">
<h1>{{testMessage}}</h1>
</body>
app.js
var app = angular.module('yourApp').controller('yourController', ['$scope', function($scope) {
$scope.testMessage = "Hello World";
}])
至于你关于处理将被编辑的数据的第二个问题,我建议你自己试一试。看着,看着。这些应该可以帮助你开始。试一试之后,如果你仍在挣扎,请针对你正在挣扎的具体问题提出一个新问题。让我试试。。。我会回来更新的。谢谢你的帮助,谢谢你的回答。我已经调整了html,以便可以使用角度指令显示数据。
var app = angular.module('yourApp').controller('yourController', ['$scope', function($scope) {
$scope.testMessage = "Hello World";
}])