AlexanderBelov
@AlexanderBelov
Frontend developer

Как юзать JQuery в Angular2 / Webpack?

Как подключить и безболезненно юзать JQuery в пачке Angular2 / Webpack?

Пытаюсь делать так:

import { Component, OnInit } from '@angular/core';
declare var $: any;

@Component({
  selector: 'catalog',
  templateUrl: './catalog.component.html',
  styleUrls: ['./catalog.component.scss']
})

export class CatalogComponent implements OnInit {
	public products: any;

	constructor(){ }  
      
        interface JQuery extends CatalogComponent {
           public  carousel(): any; 
       }

	ngOnInit(){
		this.products = 
		[
		    {
		      "id":"id-1,
		      "title": "Product 1",
		      "description": "Product One Description",
		      "price": 68720,
		      "quantity": " "
		    },
                     
                      {
		      "id":"id-2,
		      "title": "Product 2",
		      "description": "Product Two Description",
		      "price": 68720,
		      "quantity": " "
		    },

                    {
		      "id":"id-3,
		      "title": "Product 3",
		      "description": "Product Three Description",
		      "price": 68720,
		      "quantity": " "
		    },
		];

                	//Carousel
		$('.multi-item-carousel').carousel({
			interval: false
		});

		
		$('.multi-item-carousel .item').each(function(){
			var next = $(this).next();
			if (!next.length) {
			next = $(this).siblings(':first');
		}
		
			next.children(':first-child').clone().appendTo($(this));
			  
			if (next.next().length>0) {
				next.next().children(':first-child').clone().appendTo($(this));
			} else {
				$(this).siblings(':first').children(':first-child').clone().appendTo($(this));
			}
		});

		
	}

}


Консоль в ответ делает так:
9340db770ec44e8ab47f80e13353efcc.png
  • Вопрос задан
  • 769 просмотров
Пригласить эксперта
Ответы на вопрос 1
kalyukdo
@kalyukdo
Frontend developer
зачем вы это делаете??? не нужно это делать! если вы берете фреймворк типо ангуляра, незачем в него мешать библиотеки типо JQ, это бессмысленно и не верно, так как там есть все уже в ангуляре, + манипуляция с домом запрещена!
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы