Angular1 and swiper, angular1swiper

Source: Internet
Author: User

Angular1 and swiper, angular1swiper
Swiper cannot be used during angular1 route switching.

Question 1: When angular1 is used, many people write swiper Initialization on the parent controller of the template, which may cause a problem, the swiper Initialization is only performed once when the page is loaded. During the Routing Switching process, the template is reloaded, but the swiper Initialization is not performed. Therefore, swiper is not easy to use.

Solution:You can put the swiper initialization in the controller corresponding to the template..

Question 2: Put the swiper initialization in the corresponding controller. If it is still unavailable. The main reason is the initialization of swiper.

Solution:It is bestA one-time timer is added to the swiper initialization.To properly delay initialization for a short period of time, which can also solve the Skip Problem Caused by swiper loop playback..

The following is part of the demo code. You can refer to it! Index.html 1 <div class = "swiper-container"> 2 <div class = "swiper-wrapper"> 3 <div class = "swiper-slide" ng-repeat = "I in imgs "> 4 5 </div> 6 </div> 7 <div class =" swiper-pagination "> 8 9 </div> 10 </div>Swiper's html TEMPLATE 1 app. controller ("ctrl1", ["$ scope", "$ timeout", function ($ scope, $ timeout) {2 $ scope. imgs = [3 "img/banner1.jpg", 4 "img/banner2.jpg", 5 "img/banner3.jpg" 6]; 7 8 $ timeout (function () {9 new Swiper (". swiper-container ", {10 pagination :". swiper-pagination ", 11 loop: true, 12/* 13 start the dynamic Checker (OB/Viewer), when changing the swiper style (such as hide/show) or, swiper is automatically initialized when the sub-element of swiper is modified. 14 The default false15 attribute can also solve the swiper initialization problem, but when the loop attribute is enabled, there is a carousel jump problem. 16 **/17 // obverser: true18}); 19}, 100); 20 21}]);Controller corresponding to the swiper Template

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.