在登录页面中,我在提交页面时有这个功能:
checkLogin(){
this.x_userS.getLogin(this.x_userO.login_name, this.x_userO.pwd_plain).then(response => this.x_userO=response);
(function(){
setTimeout(() => {
if (this.x_userO.login_status == "1") {
this.x_companyS.getCompanyByUser(this.x_userO.user_id).then(response => this.x_companyO=response);
(function(){setTimeout(() => {
this.x_userS.setUser(this.x_userO);
this.x_companyS.setCompany(this.x_companyO);
this.router.navigate(['HomePage']);
}, 2000);
})();
}
else {
window.alert("oops");
}
}, 2000);
})();
}
Run Code Online (Sandbox Code Playgroud)
其中x_userS是登录服务,x_userO是用户对象.我试图在处理它之前将promises提交两秒钟来返回数据.没有setTimeout,它不会及时返回它.
我尝试删除除警报以外的所有内容,并在两秒钟后验证它发生了.但是,它无法识别function(){}中的任何其他内容,所以我相信我需要传递我的所有服务和对象.
有谁知道如何做到这一点?
我将在我的解释中参考此屏幕截图:
我已经设置了你在图片中看到的标签.我想活动标签(图片中的主页)下面有一条1px黑线,所以我使用了底边框.然而,很难看到,但粉红色的背景延伸到整行.我希望粉红色停止在标签的底部绘制,如果有边框,则排除边框(因此只比底部高1px).
.main_tabs{
width:100%;
display:inline-block;
background:#FFDEFD;
}
li.active a, li.active{
background:#fff;
color:#4c4c4c;
border-radius: 3px 3px 0px 0px;
border-bottom-color:#000000;
border-bottom-width:1px;
border-bottom-style:solid;
transition:all linear 0.4s;
}
Run Code Online (Sandbox Code Playgroud)
上面是我的main_tabs(负责粉红色背景)和活动标签的CSS.在main_tabs中,我尝试过使用背景大小,但它没有改变任何东西.我试图摆弄宽度和显示,但它完全搞砸了我的标签.
我目前正在尝试制作这样的20秒计时器:
this.timer = Observable.interval(1000).take(20).map((tick) => tick+1).subscribe((tick) => {
this.reverseTimer = 20-tick;
})
Run Code Online (Sandbox Code Playgroud)
如果我让Observable每次都达到20,这很好,但有时候,我想提前结束计时器.现在,我不能停止计时器,直到它在20秒后自动停止.
现在,当我希望它停止时,我将计时器隐藏在显示器中,但我需要它才能重新启动.如果我尝试在20秒之前重新启动计时器,则reverseTimer在新计时器和旧计时器值之间闪烁,因为我没有停止旧计时器.
我试过,this.timer.unsubscribe()但我得到了unsubscribe计时器不存在的错误.
我app.component包含<nav>网站的,[routerLink]用于转到不同的页面。它导入每个页面的组件。页面之一是登录页面。如果用户未登录,我希望导航显示“登录”-如果用户是“注销”。
在app.component:
my_userO : userO = undefined;
constructor (private my_userS:userS){
my_userS.userChanged.suscribe(temp => this.updateNav());
updateNav(){
this.my_userO = this.my_userS.getUser();
}
logOut(){
this.my_userS.setUser(undefined);
}
Run Code Online (Sandbox Code Playgroud)
并在其模板中:
<li><a *ngIf="!my_userO" [routerLink]="['LoginPage']">Login</a></li>
<li><a *ngIf="my_userO" [routerLink]="['HomePage']"(click)="logOut()">Logout</a></li>
Run Code Online (Sandbox Code Playgroud)
userS是一个全局服务(它是自举的main.ts,没有在我使用它的任何组件中作为提供程序添加),我看起来像这样:
public userChanged: EventEmitter<{}>
currentUser : userO = undefined;
constructor(private http:Http){
this.userChanged = new EventEmitter();
}
getLogin(username: string, password: string): Promise<userO>{
return this.http.get(this.getLoginUrl+username).toPromise().then(response => response.json().data).catch(this.handleError);
}
getUser(){
return this.currentUser;
}
setUser(x_userO: userO){
this.currentUser = x_userO;
this.userChanged.emit(undefined);
}
Run Code Online (Sandbox Code Playgroud)
在登录页面,我就跑getLogin,然后setUser …