我是角度的新手。
我使用包ng2-bootstrap使用引导模式。
我的视图文件是
<div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title pull-left">Area Master</h4>
<button type="button" class="close pull-right" (click)="lgModal.hide();" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Modal Content here...
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</div>
</div>
</div>
我需要知道如何在组件中显示/隐藏此模式(类型脚本文件)。
类型脚本文件是
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { Router } from '@angular/router';
import { FormGroup, Validators, FormBuilder, FormControl } from '@angular/forms';
import { Area } from './area';
import { AreaService } from './area.service';
@Component({
moduleId: module.id,
selector: 'my-areas',
templateUrl: './areas.component.html',
styleUrls: ['./areas.component.css']
})
export class AreasComponent implements OnInit {
area_form: FormGroup;
new_area: Area;
areas: Area[];
@ViewChild('lgModal') lgModal:ElementRef;
constructor(
private areaService: AreaService,
private router: Router,
private form_builder: FormBuilder) { }
getAreas(): void {
this.areaService
.getAreas()
.then(areas => this.areas = areas);
}
submit(area: Area): void {
console.log(area);
this.areaService.create(area)
.then(area => { this.areas.push(area) })
}
ngOnInit(): void {
this.getAreas();
this.lgModal.show();
this.area_form = this.form_builder.group({
name: ['', Validators.required],
pincode: ['', Validators.required],
status: ['Active'],
type: ['Busines Service Area']
})
}
}