我想使用Type Script从角度为2的存储数组中删除一个项目.我正在使用名为Data Service的服务,即DataService代码:
export class DataService{
private data:string[]=[];
addData(msg:string)
{
this.data.push(msg);
}
getData()
{
return this.data;
}
deleteMsg(msg:string)
{
delete[this.data.indexOf(msg)];
}
}
Run Code Online (Sandbox Code Playgroud)
和我的组件类:
import { Component } from '@angular/core'
import { LogService } from './log.service'
import { DataService } from './data.service'
@Component({
selector:'tests',
template:
`
<div class="container">
<h2>Testing Component</h2>
<div class="row">
<input type="text" placeholder="log meassage" #logo>
<button class="btn btn-md btn-primary" (click)="logM(logo.value)">log</button>
<button class="btn btn-md btn-success" (click)="store(logo.value)">store</button>
<button class="btn btn-md btn-danger" (click)="send()">send</button>
<button class="btn btn-md " (click)="show()">Show Storage</button>
<button …Run Code Online (Sandbox Code Playgroud)