angular路由切换后 轮播以及iscrollJs失效的问题

我们在使用angular的时候,路由总是最让人头疼的地方。

在这里给大家解决一些来回切换遗留下的小问题

比如我们在使用ng-route时主页面含有轮播图,当你切换到其他页面再切回主页面时会发现主页面的轮播图不会动。

对于这个问题我们要用到angular的一个指令

初始化 ng-init,

html

<div ng-init='init()'>路由过来的页面</div>  //包含轮播图

这里说明一下,我的控制器写在body中,名为ctrl

js

var app = angular.module('app',[''ng-Route]);

app.controller('ctrl',function($scope,$timeout){
    
   $scope.init = function(){
      $timeout(function(){
  //你的轮播代码,scroll也可

},100)  
  
    } 
})

这样就可以了

原文地址:https://www.cnblogs.com/UniverseWang/p/7100818.html