如何使用角度材质在角度8中创建轮播?

时间:2019-10-07 06:44:00

标签: angular angular-material angular-material-6

第一个图像是我当前正在获得的图像,第二个图像是我实际上想要的图像

  

第一位:-

enter image description here

  

第二个:-

enter image description here

<mat-card class="carousel-data">
    <mat-grid-list cols="2" rowHeight="30px" class="carousel-data" *ngFor="let data of resource let i = index;" (click)="showdata()" >

        <mat-grid-tile>     
           <img class="m-t-0 m-b-0 "[src]="data.img" alt="" width="24">
            <div class="prof-left" style="margin-left: 10px;">
                <p class="m-t-0 m-b-0 bank-name">{{ data.bank_name}}</p>
                <p class="m-t-0 m-b-0 bank-account">{{ data.account_number }}</p>
            </div>
        </mat-grid-tile>
        <mat-grid-tile>
            <div class="prof-right">
                <p class="m-t-0 m-b-0 total-bal">Total Bal</p>
                <p class="m-t-0 m-b-0 total-amount">{{ data.amount }}</p>
            </div>
        </mat-grid-tile>
    </mat-grid-list>
</mat-card>

enter image description here

4 个答案:

答案 0 :(得分:1)

            **Steps Needs to follow to achieve Carousel:-**

1。 ng new owl-carousel                 
                 2。 npm install ngx-owl-carousel owl.carousel jquery --save                 
                 3。 Add library files in angular.json

            "styles": [
            "src/styles.css",
            "./node_modules/owl.carousel/dist/assets/owl.carousel.min.css",
            "./node_modules/owl.carousel/dist/assets/owl.theme.default.min.css"
            ],
            "scripts": ["./node_modules/jquery/dist/jquery.min.js",
            "./node_modules/owl.carousel/dist/owl.carousel.min.js"]
            },
            <br><br>

           **4.** `Update app.module.ts file`<br>
                import { OwlModule } from 'ngx-owl-carousel';
                // Add OwlModule to imports at below section
                imports: [BrowserModule, OwlModule],
                <br><br>

5。Update app.component.ts file
                mySlideImages = ['../assets/images/image1.jpg','../assets/images/image2.jpeg','../assets/images/image3.jpg'];
                mySlideOptions = {项目:1,点:true,导航:true};                 

  6。 Update app.component.html file
                                                                                                                           
                有关详细信息,您可以点击此链接Carousel

答案 1 :(得分:0)

您可以使用OWl Carousel之类的东西

 <div class="owl-carousel owl-theme">
       <div class="item" *ngFor="let data of resource let i = index;">
 <mat-grid-list cols="2" rowHeight="30px" class="carousel-data"  (click)="showdata()" >

        <mat-grid-tile>     
           <img class="m-t-0 m-b-0 "[src]="data.img" alt="" width="24">
            <div class="prof-left" style="margin-left: 10px;">
                <p class="m-t-0 m-b-0 bank-name">{{ data.bank_name}}</p>
                <p class="m-t-0 m-b-0 bank-account">{{ data.account_number }}</p>
            </div>
        </mat-grid-tile>
        <mat-grid-tile>
            <div class="prof-right">
                <p class="m-t-0 m-b-0 total-bal">Total Bal</p>
                <p class="m-t-0 m-b-0 total-amount">{{ data.amount }}</p>
            </div>
        </mat-grid-tile>
    </mat-grid-list>
    </div>
    </div>

在您的componenet中

ngAfterViewInit(){
    $('.owl-carousel').owlCarousel({
    loop:true,
    margin:10,
    nav:true,
    responsive:{
        0:{
            items:1
        },
        600:{
            items:3
        },
        1000:{
            items:5
        }
    }
   })
  }

Check this demo to see how to use with angular

请注意,必须包含jquery和owl carousel文件才能使其正常工作

或者您可以使用ngx-owl-carousel

答案 2 :(得分:0)

如果您已经包含,则可以尝试使用自举轮播,例如 https://www.w3schools.com/bootstrap/bootstrap_carousel.asp

或其他类似wich的依赖非常简单,并且在此链接中提到了步骤

https://www.npmjs.com/package/@ngu/carousel

答案 3 :(得分:0)

运行 yarn添加ngx-owl-carousel-o npm install ngx-owl-carousel-o ng添加ngx-owl-carousel-o

添加样式(这些变体之一)。 src/styles.sasssrc/styles.scss

@import '~ngx-owl-carousel-o/lib/styles/scss/owl.carousel';
@import '~ngx-owl-carousel-o/lib/styles/scss/owl.theme.default';

Import RoutingModule和进入AppModule的路由,除非它们被导入。

Import BrowserAnimationsModuleAppModule中,除非已导入。

Import CarouselModule插入到一个模块中,该模块声明一个打算具有转盘的组件。

import { CarouselModule } from 'ngx-owl-carousel-o';
@NgModule({
  imports: [ CarouselModule ],
  declarations: [ CarouselHolderComponent ]
})
export class SomeModule { }

添加到所需组件的customOptions或以不同方式命名的对象以及轮播选项:

import { OwlOptions } from 'ngx-owl-carousel-o';
@Component({
  selector: '....',
  templateUrl: 'carousel-holder.component.html'
})
export class CarouselHolderComponent {
  customOptions: OwlOptions = {
    loop: true,
    mouseDrag: false,
    touchDrag: false,
    pullDrag: false,
    dots: false,
    navSpeed: 700,
    navText: ['', ''],
    responsive: {
      0: {
        items: 1
      },
      400: {
        items: 2
      },
      740: {
        items: 3
      },
      940: {
        items: 4
      }
    },
    nav: true
  }
}
Add html-markup to the template of the component (in this case, add it to carousel-holder.component.html):

  <div>Some tags before</div>
    <owl-carousel-o [options]="customOptions">
    <ng-template carouselSlide>Slide 1</ng-template>  
    <ng-template carouselSlide>Slide 2</ng-template>  
    <ng-template carouselSlide>Slide 3</ng-template>  
  </owl-carousel-o>
  <div>Some tags after</div>

<div>Some tags before</div>
    <owl-carousel-o [options]="customOptions">

    <ng-container *ngFor="let slide of slidesStore">
      <ng-template carouselSlide [id]="slide.id">
        <img [src]="slide.src" [alt]="slide.alt" [title]="slide.title">
      </ng-template>
    </ng-container>

  </owl-carousel-o>
  <div>Some tags after</div>

please follow this link