我是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 ....我怎么能解决这个问题.
如何使用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)