我正在尝试构建一个指令来处理重复发言者列表的呈现。这里的最终目标是让页面自动反映在模式中所做的更新。
我在这里看到的问题是该speakers
对象似乎没有进入模板。
这是填充的函数speakers
。它在模态的承诺中被调用。 speakers
是speaker
对象的集合。数据按预期返回。
$scope.updateSpeakersList = function () {
factory.callGetService("GetSpeakers?eventId=" + $scope.event.eventId)
.then(function (response) {
var fullResult = angular.fromJson(response);
var serviceResponse = JSON.parse(fullResult.data);
$scope.speakers = serviceResponse.Content;
if ($scope.speakers === null) {
$scope.hasSpeakers = false;
} else {
$scope.hasSpeakers = ($scope.speakers.length > 0);
}
LogErrors(serviceResponse.Errors);
},
function (data) {
console.log("Unknown error occurred calling GetSpeakers");
console.log(data);
});
}
// other code... then this
modalInstance.result.then(function (savedSpeaker) {
console.log("BEGIN modalInstance.result");
$scope.savedSpeaker = savedSpeaker;
console.log("$scope.savedSpeaker = " + $scope.savedSpeaker);
$scope.updateSpeakersList();
console.log("END modalInstance.result");
}, function () {
console.log("Modal dismissed at: " + new Date());
});
HTML 看起来像这样。
<div class="container" ng-show="hasSpeakers">
<div class="row">
<speaker-cards data="speakers"></speaker-cards>
</div>
</div>
该指令非常简单。
.directive("speakerCards", function() {
return {
restrict: "E",
templateUrl: "/Apps/Event/Templates/_default/speaker-cards.html",
scope: {
data: "="
}
};
});
“演讲者卡”模板比这要复杂一些,但您应该明白这一点。
<!-- BEGIN speaker cards -->
<div ng-repeat="speaker in speakers | orderBy: 'SpeakerName'">
<div class="clearfix" ng-if="$index % 3 == 0"></div>
<div class="col-sm-4">
<div class="card">
<span class="speaker-name">{{speaker.SpeakerName}}</span><br/>
<span class="speaker-title">{{speaker.CompanyTitle}}</span><br/>
<span class="speaker-company">{{speaker.CompanyName}}</span>
</div>
</div>
</div>
<!-- END speaker cards -->
除了没有出现演讲者之外,我认为没有speakers
将其放入模板的原因是因为生成的标记看起来像这样。