小编Daa*_*v z的帖子

当变量发生变化时,NgIf不会更新

是的,所以我有一个包含以下模板的标题组件(navbar):

<ng-template [ngIf] = "authService.isAuthenticated()">
  <li>
    <a routerLink="Landing" class="navbar-brand" (click)="Logout()"><span class="xvrfont">Logout</span><i class="fa fa-sign-in" aria-hidden="true"></i></a>
  </li>
  <li>
    <a routerLink="Profile" class="navbar-brand"><span class="xvrfont">{{authService.getUsername()}}</span><i class="fa fa-user-circle" aria-hidden="true"></i></a>
  </li>
</ng-template>
Run Code Online (Sandbox Code Playgroud)

当用户通过身份验证时,导航的这一部分应该是可见的.找出它通过authService检查.

要检查用户是否已通过身份验证,将在每次路由更改时运行以下代码:

checkAuthenticated(){
   if  (localStorage.getItem('token') != null){ this.authenticated = true; }
   else { this.authenticated = false; }
   console.log(this.authenticated); // for Debugging. 
}
Run Code Online (Sandbox Code Playgroud)

NgIf语句调用此方法:

public isAuthenticated(){
     return this.authenticated;
}
Run Code Online (Sandbox Code Playgroud)

根据日志,"证实" 真假之间切换正确,但Ngif不响应的变化不知何故.

标头component.ts看起来像这样:

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import {AuthService} from "../auth/auth.service";

@Component({
  selector: 'app-header',
  providers: [AuthService],
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css'],
  encapsulation: ViewEncapsulation.None …
Run Code Online (Sandbox Code Playgroud)

service typescript angular-ng-if angular

6
推荐指数
2
解决办法
1万
查看次数

使用 Java 中的 Robot 类模拟“Fn”按键

我正在尝试编写一个小程序,每当我收到电子邮件/文本/其他类型的消息时,它都会使我的笔记本电脑键盘的背光闪烁。我正在尝试使用 Java 的 Robot 类来执行此操作。

到目前为止,我的问题是我似乎找不到“Fn”键的键码。

java awtrobot

3
推荐指数
1
解决办法
2288
查看次数

检查值是私有还是只读

说我有一节课:

export class ItemType{

  readonly itemtype_id: number;
  public name :string;

  constructor(itemtype_id: number, name: string) {
    this.itemtype_id = itemtype_id;
    this.name = name;
  }
}
Run Code Online (Sandbox Code Playgroud)

现在我已经创建了一个可编辑标签的单独组件.

<div class="row">
  <div class="col-xs-4">
    <h4><span class="xvrfont padding">{{label}}</span></h4>
  </div>
  <div class="col-xs-2"></div>
  <div class="col-xs-5">

    <div *ngIf="editing">
      <input #editableField
             [required]="required"
             (blur)="onBlur($event)"
             [name]="value"
             [(ngModel)]="value"
             [type]="type"
             [placeholder]="label"
             (keyup.enter)="onEnter()"
             (mouseover)="$event.target.select()"
             />
    </div>
    <div *ngIf="!editing">
      <h4 title="Click to edit" (click)="edit(value);" (focus)="edit(value);" tabindex="0" class="inline-edit">{{value}}&nbsp;</h4>
    </div>


  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

当我调用此组件时,我希望该字段可以根据属性是否为只读来编辑.如果该属性是只读的,则该字段不应该是可编辑的.如果不是,它应该.

<app-editable-field [isEditable]={{**check if the property is readonly**}} label='Label" [required]="true" type="text"></app-editable-field>
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以检查类中的属性是否为readOnly/private?

typescript angular

2
推荐指数
1
解决办法
273
查看次数

从标记中的对象获取属性

对于学校作业,我们在C#中制作国际象棋游戏,我们必须学会以面向对象的方式工作.该板由嵌套for循环中的2D图片盒阵列构成

//Create the Board Pattern out of PictureBoxes
        #region Checkerboard

        PictureBox[,] Vak = new PictureBox[8, 8];

        for (int i = 0; i < 8; i++)
        {
            for (int x = 0; x < 8; x++)
            {

                Vak[i, x] = new PictureBox();
                Vak[i, x].Name = String.Format("{0},{1}", i, x);
                Vak[i, x].Width = 50;
                Vak[i, x].Height = 50;
                Vak[i, x].Location = new Point(xpos, ypos);
                Vak[i, x].SizeMode = PictureBoxSizeMode.Zoom;
                Vak[i, x].Click += Chess_Click;
                if ((i + x) % 2 == 0)
                {
                    Vak[i, x].BackColor …
Run Code Online (Sandbox Code Playgroud)

.net c# chess

1
推荐指数
1
解决办法
798
查看次数

标签 统计

angular ×2

typescript ×2

.net ×1

angular-ng-if ×1

awtrobot ×1

c# ×1

chess ×1

java ×1

service ×1