元件內加入 <script>內容

1 篇文章 / 0 new
author
元件內加入 <script>內容
import { Component, OnInit,  Renderer2, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
 
export class AdminComponent implements OnInit {
 
    constructor(private _renderer2: Renderer2, @Inject(DOCUMENT) private _document) {
        //
        let s = this._renderer2.createElement('script');
        s.type = `text/javascript`;
        s.text = `$(document).ready(function () {
            $('#sidebarCollapse').on('click', function () {
                $('#sidebar').toggleClass('active');
                if(!$("#sidebar").hasClass("active")) {
                    $('#sidebarCollapse').addClass('hideBtn');
                } else {
                    $('#sidebarCollapse').removeClass('hideBtn');
                }
            });
            $('#closeSidebar').on('click', function () {
                $('#sidebar').toggleClass('active');
                if(!$("#sidebar").hasClass("active")) {
                    $('#sidebarCollapse').addClass('hideBtn');
                } else {
                    $('#sidebarCollapse').removeClass('hideBtn');
                }
            });
        });`;
        this._renderer2.appendChild(this._document.body, s);
    } 
Free Web Hosting