小编jav*_*ens的帖子

使用 ngx-bootstrap modal 将数据传递给 modal

我正在使用 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">&times;</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)

typescript ngx-bootstrap angular

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

角度定位

我被困在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)

typescript angular

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

使用 startsWith 作为自定义管道

实际上我想使用*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)

html javascript typescript angular

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

标签 统计

angular ×3

typescript ×3

html ×1

javascript ×1

ngx-bootstrap ×1