在 Angular2 项目中包括 adminLTE



我试图在我的角度项目 2 中包含adminlte模板。我把adminlte文件夹放在node_modules里面,但是当在角index.html中链接.js.css时,它找不到它们,我不知道为什么原因。谁能就这个话题向我提出建议?

附加代码和错误:

参考

错误

答案不会那么容易。

根据AdminLTE网站"https://almsaeedstudio.com/themes/AdminLTE/documentation/index.html">

有没有像Yii或Symfony这样的PHP框架的集成指南?

简短的回答,没有。但是,有围绕 提供有关如何与许多不同集成的信息的网络 框架。甚至还有集成的AdminLTE版本。 使用 jQuery ajax、AngularJS 和/或 MVC5 ASP .NET。

所以你可以检查这个

  • https://www.npmjs.com/package/ng2-admin-lte

但我认为如果您使用的是 Angular CLI,您可以在项目的"资产"文件夹中添加"引导、dist、包">

我假设包含模板意味着在您的应用程序中使用 AdminLTE.css 文件。

为此,您需要将.css文件导入到组件.ts文件中,如下所示:

@Component({
moduleId: module.id,
selector: 'dashboard',
templateUrl: 'dashboard.component.html',
styleUrls: ['bower_components/adminLTE/dist/css/AdminLTE.min.css']
})

PS:确保路径有效

指定 styleUrl 后,我们将能够访问 Admin LTE 的 CSS 选择器或 dashboard.component.html 文件中的任何其他模板。

有几种方法可以将CSS添加到您的角度项目中,请参阅以下链接: https://scotch.io/tutorials/all-the-ways-to-add-css-to-angular-2-components

一个有趣的方法是通过 angular-cli 添加,如下面的 git 集线器链接所示 https://github.com/ahmadalibaloch/Angular-AdminLTE

我在github中找到了一个Angular 2端口的AdminLTE。你可能想看看这个:

https://github.com/csotomon/Angular2-AdminLTE

由于CodingFriday上的视频,我能够将AdminLte集成到我的Angular项目中。我还能够添加路由,现在我有了网站的主页和带有动画的管理页面。我是Web编程的新手,我的项目有很多糟糕的解决方案(这是我大学的一门课程),但也许这会帮助某人入门。

https://github.com/paulrozhkin/tamagotchi-web-client

简而言之,应该采取以下步骤(步骤的来源是通过编码星期五在github上的指南):

  1. 在您的项目中安装管理员 lte 3:

    npm install admin-lte@^3.0 --save
    
  2. 选择仪表板并将所有链接样式和脚本从仪表板复制到 angular.json:

    例如,这是仪表板 2 的更新 angular.json 文件。

    "styles": [
    ...
    "node_modules/admin-lte/plugins/fontawesome-free/css/all.min.css",
    "node_modules/admin-lte/plugins/overlayScrollbars/css/OverlayScrollbars.min.css",
    "node_modules/admin-lte/docs_html/assets/css/adminlte.css"
    ],
    "scripts": [
    ...
    "node_modules/admin-lte/plugins/jquery/jquery.js",
    "node_modules/admin-lte/plugins/bootstrap/js/bootstrap.bundle.js",
    "node_modules/admin-lte/plugins/overlayScrollbars/js/jquery.overlayScrollbars.js",
    "node_modules/admin-lte/dist/js/adminlte.js",
    "node_modules/admin-lte/dist/js/demo.js",
    "node_modules/admin-lte/plugins/jquery-mousewheel/jquery.mousewheel.js",
    "node_modules/admin-lte/plugins/raphael/raphael.js",
    "node_modules/admin-lte/plugins/jquery-mapael/jquery.mapael.js",
    "node_modules/admin-lte/plugins/jquery-mapael/maps/usa_states.js",
    "node_modules/admin-lte/plugins/chart.js/Chart.js",
    "node_modules/admin-lte/dist/js/pages/dashboard2.js"
    ]
    
  3. 将仪表板中的正文类添加到您的正文。

    对于仪表板 2,这可能是:

    <body class="hold-transition sidebar-mini layout-fixed layout-navbar-fixed layout-footer-fixed">
    
  4. 创建新组件并将仪表板正文从索引复制到模板

  5. 将图像复制到资产文件夹 - 从node_modulesadmin-ltedistimgassets

  6. 将路径图像替换为src="assets/<image-name>"


描述我的集成后续步骤。我不能保证这些是最好的解决方案,可能会有更好的解决方案。当我将路由添加到管理面板时,我遇到了以下问题:

  1. 正文类不应应用于其余部分,管理面板除外。

    溶液:

    • Renderer2导入管理面板组件。

    • OnInit管理面板挂钩中,这些类是使用以下方法添加的:

      Renderer2.addClass (...)
      
    • ngOnDestroy管理面板挂钩中,可以使用以下命令删除这些类:

      Renderer2.removeClass(...)
      
  2. 路由后,js 动画停止工作。

    溶液:

    • adminlte.js复制到资产(也更改 angular.json 中的路径)并替换:

      $(window).on('load', function ()
      

      $( document ).ready(function()
      
    • 此外,如果要在路由后启动仪表板动画(设置地图、图表数据),则必须从仪表板面板上的隐藏代码启动它。

最新更新