我正在使用 AngularJS 和 Reveal.js 创建幻灯片。显示要求表格
<div class="slides">
<section>
</section>
</div>
用于水平幻灯片。虽然垂直幻灯片有两个部分:
<div class="slides">
<section>
<section>
</section>
</section>
</div>
我正在使用角度呈现此页面:
<div ng-app='myApp' class="reveal">
<div class="slides" ng-controller='MyController'>
<section slide ng-repeat="slide in slides">
</section>
</div>
</div>
<script src="https://raw.github.com/hakimel/reveal.js/master/js/reveal.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js"></script>
</body>
</html>
具有多个步骤的幻灯片应该是垂直的。所有其他都应该是水平的。控制器返回步骤并设置 Reveal:
function MyController($scope) {
$scope.slides = [
{ 'steps': ['a'] },
{ 'steps': ['b1', 'b2'] },
{ 'steps': ['c1'] }
];
setTimeout(function() {
Reveal.initialize({
loop: false,
transition: Reveal.getQueryHash().transition || 'none'
});
}, .1 * 1000);
}
该指令需要在步骤周围添加一个新元素和属性。这是我丑陋的、令人尴尬的、命令式的、类似 jQuery 的指令:
app.directive('slide', function () {
var wrapContent = function (content) {
return '<h1>' + content + '</h1>';
};
return {
restrict: 'A'
,link: function (scope, element, attrs, controller) {
// resorting to imparative jQuery way
if (scope.slide.steps.length == 1) {
element.html(
wrapContent(scope.slide.steps[0])
);
} else {
var sections = '';
for (i=0,len=scope.slide.steps.length; i < len; ++i) {
sections +=
'<section ' +
function () {
result = '';
if (i !== len-1) {
result = 'data-autoslide="1000" ';
}
return result;
}() +
'>' +
wrapContent(scope.slide.steps[i]) +
'</section>';
}
element.html(sections);
}
}
}
});
我如何编写它使其看起来像角度代码?jsfiddle
我试过编译、链接、替换、ng-switch 都无济于事。