我使用AngularJS和Reveal.js创建幻灯片。显示需要表格声明编写* wrapper *指令AngularJS
<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>
幻灯片与多发步骤应该是垂直的。所有其他人应该是水平的。控制器返回步骤并设置显示:
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都无济于事。
在链接结束时初始化3方lib消除了愚蠢的'setTimeout'。谢谢。 OTOH,这仍然比角度更强调。 – zhon 2013-02-09 06:21:40
当然,在Angular中看到的古典声明式风格是必要的。但是,Reveal.js对于它所期望的DOM是如此具体,并且渲染内容的逻辑足够复杂,所以我可能会在实际项目中以这种方式编写它,因为我相信它更具可读性。(我实际上还没有成功创建此指令的声明版本。) – 2013-02-09 08:50:26