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); }
元件內加入 <script>內容
週一, 2018-03-05 19:46
#1
元件內加入 <script>內容