Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular 6样式在首次登录/导航后未正确加载_Javascript_Html_Angular_Typescript_Sass - Fatal编程技术网

Javascript Angular 6样式在首次登录/导航后未正确加载

Javascript Angular 6样式在首次登录/导航后未正确加载,javascript,html,angular,typescript,sass,Javascript,Html,Angular,Typescript,Sass,正如标题中所说,css样式似乎没有正确加载。仅在重新加载页面之后 首先登录时: 然后在页面刷新后: 我的应用程序路由: const appRoutes: Routes = [ { path: '', canActivateChild: [AuthGuard], children: [ { path: 'auth', component: UnauthenticatedContainerComponent,

正如标题中所说,css样式似乎没有正确加载。仅在重新加载页面之后

首先登录时:

然后在页面刷新后:

我的应用程序路由:

const appRoutes: Routes = [
  {
    path: '',
    canActivateChild: [AuthGuard],
    children: [
      {
        path: 'auth',
        component: UnauthenticatedContainerComponent,
        data: { excludeLogin: true },
        children: [
          { path: 'login', component: LoginComponent },
        ],
      },
      {
        path: '',
        component: AuthenticatedContainerComponent,
        data: { requireLogin: true },
        children: [
          {
            path: '',
            component: RequestContainerComponent,
            children: [
              { path: 'requests/list', component: RequestListComponent },
              { path: 'request', component: RequestComponent },
              { path: 'results/:id', component: RequestResultListComponent, canActivate: [TabGuard] },
            ],
          },
          {
            path: 'maintenance',
            component: MaintenanceComponent,
          },
          {
            path: 'settings',
            component: SettingsComponent,
          },
          {
            path: 'administration',
            component: AdminComponent,
          },
          {
            path: 'train',
            component: TrainComponent,
          },
        ],
      },
    ],
  },
  { path: '**', redirectTo: '/' },
];

在Angular 6中,您必须将css文件导入Angular.json文件,如下所示:

{
  ...
  projects: {
    [project_name]: {
      ...
      architect: {
        build: {
          ...
          options: {
            styles:{
              "src/styles.scss"
            }
          }
        }
      }
    }
  }
}
此styles.scss是项目的主样式表文件,但您也可以通过在组件声明中添加以下内容来处理单独的组件:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

好吧,糟糕,我找到了答案:

在我的LoginComponent中,我使用了
ViewEncapsulation.NONE
,它是以前开发人员的翻版,因此我删除了它,现在它工作正常


请参阅:

浏览器网络选项卡中是否有任何失败的CSS请求?如果没有,CSS请求会给出什么响应?浏览器控制台或网络中没有错误<代码>CSS请求的响应是什么?我如何测试它?在浏览器网络选项卡中,只需查看CSS请求的HTTP响应第一次登录时无任何响应,刷新时我有roboto
https://fonts.googleapis.com/css?family=Roboto:100,400700900
。Edit只是完全删除了它,同样的behaviorok,所以它甚至没有在第一次登录时请求css?这不是这里的问题。我的主样式文件是这样导入的。