小编Jan*_*hCW的帖子

使用Typescript隐藏元素

我是Typescript和Angular Material的新手.我想在这样的元素中隐藏元素.

<div id="abc">
   <div id="123">
      <p>Hello!</p>
   </div>
      <p>World</p>
</div>
<div id="def">
    <p>Hello World</p>
</div>
Run Code Online (Sandbox Code Playgroud)

我想隐藏div块(id:123).我试过这种方式.

var formElement = <HTMLFormElement>document.getElementById('123');
formElement.style.display='block';
Run Code Online (Sandbox Code Playgroud)

它得到一个错误,说无法读取属性'样式'的null ....我怎么能解决这个问题.

html typescript angular

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

如何使用打字稿设置Angular 4中的文本框值?

如何使用TypeScript在Angular 4中设置文本框值?我以这种方式尝试过,但是没有用。

app.component.html

<form class="example-form">
  <mat-form-field class="example-full-width">
     <input matInput class='aaaa' placeholder="Favorite food" [(ngModel)]="form1" value="{{setTextBoxValue}}">
     </mat-form-field>
  <button (click)='clickMe()'>Click Me</button>
</form>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

import {Component, OnInit} from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'] 
}) 

export class AppComponent implements OnInit {
   title = 'app';
   clickMe() {
     setTextBoxValue: string = "new value";
   }
}
Run Code Online (Sandbox Code Playgroud)

html textbox typescript angular

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

标签 统计

angular ×2

html ×2

typescript ×2

textbox ×1