Home > Article > Web Front-end > Problems encountered in angular development
1. In our angular development, data will be requested but carousel images, etc... After requesting data, its events and methods will no longer be executed;
See our solution 1 :
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" }) }) }); });
Solution 2: (Although this is possible, it still has a small problem)
new Swiper(".swiper-container",{ autoplay:2000, autoplayDisableOnInteraction:false, loop:true, pagination:".swiper-pagination", observer:true, //子元素改变时自动初始化swiper observerParents:true, //修改swiper时自动初始化swiper
})//这是插件中俩方法,当子元素或父元素发生改变时 初始化这个swiper,当然这个只是swiper有相信别的也差不多有自己找找。
2. In the process of developing a single-page application with Angular routing, each page will have events to be triggered; but the one you write will die after switching.
Solution:
$scope.slide=function(){
new Swiper("#slide-rl",{
autoplay:2000,
autoplayDisableOnInteraction:false,
pagination:".swiper-pagination",
loop:true
})
<em>}<br/><br/>//把我们的代码都写在angular定义的一个方法中,在要引入的html页面调用就ok了</em>
The above is the detailed content of Problems encountered in angular development. For more information, please follow other related articles on the PHP Chinese website!