除登录页面外,我在每个页面上都有一些我想要的元素.当用户在登录页面上时,我想使用ngIf或可能的元素的隐藏属性来隐藏这些元素.
我试过这个:
<div [hidden]="router.isRouteActive(router.generate('/login'))">
Run Code Online (Sandbox Code Playgroud)
基于这个问题和答案:在Angular 2中,您如何确定活动路线?
并且还试过这个:
<div *ngIf="!router.isRouteActive(router.generate('/login'))">
Run Code Online (Sandbox Code Playgroud)
但没有取得任何成功.
这里参考的是与此html匹配的组件.
import { Component, OnInit } from 'node_modules/@angular/core';
import { HTTP_PROVIDERS, XHRBackend } from 'node_modules/@angular/http';
import { Routes, Router, ROUTER_DIRECTIVES } from 'node_modules/@angular/router';
import { LoginService } from './login/login.service';
import { LoginComponent } from './login/login.component';
import { UserComponent } from './user/user.component';
@Component({
selector: 'portal',
templateUrl: 'portal/portal.component.html',
directives: [ROUTER_DIRECTIVES, LoginComponent, UserComponent ],
providers: [
HTTP_PROVIDERS,
LoginService
]
})
@Routes([
{ path: '/login', component: LoginComponent},
{ path: '/user/:username', component: UserComponent}
]) …Run Code Online (Sandbox Code Playgroud) 我想在我的Angular 2应用程序中添加一些碎片样式,比如将在每个地方使用的字体和颜色方案.在过去,我总是通过向我的索引页面添加这样的标记来完成此操作:
<link rel="stylesheet" href="css/framework.css" />
Run Code Online (Sandbox Code Playgroud)
这不适用于CLI用于提供应用程序的任何内容.我尝试在构建之后手动将css文件添加到dist文件夹,但这似乎也不起作用.
我也尝试在这样的anugular-cli-build.js文件夹中添加css
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'css/*.css'
]
});
};
Run Code Online (Sandbox Code Playgroud)
css当我告诉它构建时,它似乎仍然没有在文件夹中构建文件.
有问题的样式表是整个应用程序的基线样式,而不是我想要包含在styleUrl标记中的样式.
localStorage我想在我的应用程序关闭时销毁持有的令牌。以前我会做这样的事情:
window.onbeforeunload\xc2\xa0=\xc2\xa0function\xc2\xa0(event)\xc2\xa0{\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0localStorage.removeItem('token');\n}; \nRun Code Online (Sandbox Code Playgroud)\n\n我不确定如何在 Angular2 中获得此功能,或者将代码放在哪里,以便它在应用程序关闭时执行。我的直觉告诉我将它放在我的应用程序级别组件中,但我无法通过谷歌搜索答案。
\n