开始

  1. ng new angular-contacts

初始化组件

  1. ng g component navbar
  2. ng g component sidebar
  3. ng g component dashboard

导入 bootstrap 和自定义样式

下载:

  1. npm i bootstrap

配置 .angular-cli.json

  1. ...
  2. "styles": [
  3. "../node_modules/bootstrap/dist/css/bootstrap.css",
  4. "styles.css"
  5. ],
  6. ...

src/styles.css 文件中写入以下内容:

  1. /* You can add global styles to this file, and also import other style files */
  2. /*
  3. * Base structure
  4. */
  5. /* Move down content because we have a fixed navbar that is 50px tall */
  6. body {
  7. padding-top: 50px;
  8. }
  9. /*
  10. * Global add-ons
  11. */
  12. .sub-header {
  13. padding-bottom: 10px;
  14. border-bottom: 1px solid #eee;
  15. }
  16. /*
  17. * Top navigation
  18. * Hide default border to remove 1px line.
  19. */
  20. .navbar-fixed-top {
  21. border: 0;
  22. }
  23. /*
  24. * Sidebar
  25. */
  26. /* Hide for mobile, show later */
  27. .sidebar {
  28. display: none;
  29. }
  30. @media (min-width: 768px) {
  31. .sidebar {
  32. position: fixed;
  33. top: 51px;
  34. bottom: 0;
  35. left: 0;
  36. z-index: 1000;
  37. display: block;
  38. padding: 20px;
  39. overflow-x: hidden;
  40. overflow-y: auto;
  41. /* Scrollable contents if viewport is shorter than content. */
  42. background-color: #f5f5f5;
  43. border-right: 1px solid #eee;
  44. }
  45. }
  46. /* Sidebar navigation */
  47. .nav-sidebar {
  48. margin-right: -21px;
  49. /* 20px padding + 1px border */
  50. margin-bottom: 20px;
  51. margin-left: -20px;
  52. }
  53. .nav-sidebar>li>a {
  54. padding-right: 20px;
  55. padding-left: 20px;
  56. }
  57. .nav-sidebar>.active>a,
  58. .nav-sidebar>.active>a:hover,
  59. .nav-sidebar>.active>a:focus {
  60. color: #fff;
  61. background-color: #428bca;
  62. }
  63. /*
  64. * Main content
  65. */
  66. .main {
  67. padding: 20px;
  68. }
  69. @media (min-width: 768px) {
  70. .main {
  71. padding-right: 40px;
  72. padding-left: 40px;
  73. }
  74. }
  75. .main .page-header {
  76. margin-top: 0;
  77. }
  78. /*
  79. * Placeholder dashboard ideas
  80. */
  81. .placeholders {
  82. margin-bottom: 30px;
  83. text-align: center;
  84. }
  85. .placeholders h4 {
  86. margin-bottom: 0;
  87. }
  88. .placeholder {
  89. margin-bottom: 20px;
  90. }
  91. .placeholder img {
  92. display: inline-block;
  93. border-radius: 50%;
  94. }

重启。

导入路由