我正在使用 angular 8 和 ngx-boostrap 打开模态并将数据从父级传递到模态。但没有按预期工作。我该怎么做才能使它工作?.. 这是我的stackblitz演示和代码
HTML
<button type="button" class="btn btn-primary" (click)="openModal(template)">Open modal</button>
<ng-template #template>
<div class="modal-header">
<h4 class="modal-title pull-left">Modal</h4>
<button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Just a modal with a {{initialState.data1}}
</div>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
成分
openModal(template: TemplateRef<any>) {
const initialState = {
data1 : 'foo'
}
this.modalRef = this.modalService.show(template, {initialState});
}
Run Code Online (Sandbox Code Playgroud) 我被困在geolocation. 实际上它工作正常,但是当我使用If else. 当用户单击允许位置时它工作但当用户单击不允许时出现问题,它不会插入else. 此DEMO作为参考。
成分
ngOnInit() {
this.getUserLocation();
}
getUserLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
});
}else {
console.log("User not allow")
}
}
Run Code Online (Sandbox Code Playgroud) 实际上我想使用*ngIf检查字符串是否以某个字符开头。
是否可以通过使用角度来做到这一点?我试过了,但出现错误
HTML
<app-breadcrumb *ngIf="startsWith:url === '/register/'"></app-breadcrumb>
Run Code Online (Sandbox Code Playgroud)
成分
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'startsWith'
})
export class UserComponent implements PipeTransform {
transform(fullText: string, textMatch: string): boolean {
return fullText.startsWith(textMatch);
}
}
Run Code Online (Sandbox Code Playgroud)