欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

angular开发中遇到的问题

程序员文章站 2022-05-17 17:59:47
...
一、在我们的angular开发中,会请求数据但轮播图等...在请求过数据后他的事件和方法将不再执行;

看我们的解决方案一:

app.controller("text",function($scope,$http,$timeout){
				$http.get("http://127.0.0.1:3333/huoqu").success(function(data){
					$scope.shuju=data.img
					$timeout(function(){ //在请求完成时,强制更新数据,强制重新运行一次,重新获取数据
						new Swiper(".swiper-container",{
							autoplay:2000,
							autoplayDisableOnInteraction:false,
							loop:true,
							pagination:".swiper-pagination"
						})
					})
				});
						
			});

  解决方案二:(这个虽然可以,但是还是有点小问题)

new Swiper(".swiper-container",{
		autoplay:2000,
		autoplayDisableOnInteraction:false,
		loop:true,
		pagination:".swiper-pagination",
          observer:true,         //子元素改变时自动初始化swiper
          observerParents:true,   //修改swiper时自动初始化swiper
	})//这是插件中俩方法,当子元素或父元素发生改变时 初始化这个swiper,当然这个只是swiper有相信别的也差不多有自己找找。		

  

二、angular在路由开发单页面应用的过程中;你每个页面都会有事件要触发;但你写的切换后就挂掉了。

解决方案:

    

$scope.slide=function(){

    new Swiper("#slide-rl",{
      autoplay:2000,
      autoplayDisableOnInteraction:false,
      pagination:".swiper-pagination",
      loop:true
    })

}

//把我们的代码都写在angular定义的一个方法中,在要引入的html页面调用就ok了

  

以上就是angular开发中遇到的问题的详细内容,更多请关注其它相关文章!