我的dashboard.component.html
<button type="button" id="sidebarCollapse" class="btn btn-info">Collapse</button>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$('#sidebarCollapse').on('click',function(){
$('#sidebar').toggleClass('active');
});
});
</script>
這與dashboard.component.html文件中的其他代碼一起完美編譯,但在ng serve之后。 單擊時,我的應用程序不執行折疊按鈕。
如果我將文件作為 index.html 和 style.css 在 Angular 框架之外單獨運行,它往往會正常工作。 問題存在於引導庫沒有被 Angular 或相關的東西執行。
我在 stackblitz 中有其余的完整功能代碼供參考https://stackblitz.com/edit/dashboardissue