[英]How do I switch div layers with a timeout function in Angularjs?
members of the Angular Technorati. Angular Technorati的成员。 I come to you with a puzzling issue, although simple.
尽管简单,但我却遇到一个令人费解的问题。 I need to switch out a div layer after about 11 seconds and show another div layer.
我需要在大约11秒钟后关闭div图层,并显示另一个div图层。 How is this done using angularjs timeout service, preferably within a controller?
如何使用angularjs超时服务(最好是在控制器内)完成此操作?
Ok, what if I combined a show and hide event with the $timeou service? 好吧,如果我将显示和隐藏事件与$ timeou服务结合在一起怎么办?
` <body ng-app="myApp">
<div ng-controller="showHideController" ng-init="getPanel_1()">
<div ng-controller="showHideController" ng-show="divA"style=''>
</div>
<div ng-controller="showHideController" ng-show="divB" style=''>
</div>
<script>
angular.module('myApp',[]).controller('showHideController',function($scope, $timeout) {
$scope.getPanel_1 = function(){
$scope.divA = true;
$scope.divB = false;
$scope.divC = false;
}
$timeout(function (){
$scope.getPanel_1 = function(){
$scope.divA = false;
$scope.divB = true;
$scope.divC = false;
}
}, 5000);
});
</script>`
Thanks in advance, Batoe. 在此先感谢Batoe。
"The road to success is filled with obstacles......but also success!" “通往成功的道路充满了障碍……但也成功!” The unknown optimist.
未知的乐观主义者。
Not very angularjs way, but you could: 不是非常的angularjs方式,但是您可以:
<div ng-controller="myCtrl">
<div ng-include src="currentDiv">
</div>
</div>
<script type="text/ng-template" id="div1.html">
<div ng-controller="panel_1">
</div>
</script>
<script type="text/ng-template" id="div2.html">
<div ng-controller="panel_2">
</div>
</script>
and in your controller: 并在您的控制器中:
app.controller('myCtrl', function($scope, $timeout) {
$scope.currentDiv= "div1.html" ;
$timeout(function () {
$scope.currentDiv= "div2.html" ;
}, 15000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.