- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在我的组件 ts 文件中导入了 OpenLayers map ,然后我创建了一个 id = map 的 div block ,其中必须显示 OpenLayers map ,但它没有。当我将 div block (#map) 移到 mat-stepper block 之外时,它就可以工作了。
组件.ts:
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import OlMap from 'ol/Map';
import OlXYZ from 'ol/source/XYZ';
import OlTileLayer from 'ol/layer/Tile';
import OlView from 'ol/View';
import { fromLonLat } from 'ol/proj';
@Component({
selector: 'app-sell',
templateUrl: './sell.component.html',
styleUrls: ['./sell.component.scss'],
})
export class SellComponent implements OnInit {
...
map: OlMap;
source: OlXYZ;
layer: OlTileLayer;
view: OlView;
...
ngOnInit() {
this.source = new OlXYZ({
url: 'http://tile.osm.org/{z}/{x}/{y}.png',
});
this.layer = new OlTileLayer({
source: this.source,
});
this.view = new OlView({
center: fromLonLat([6.661594, 50.433237]),
zoom: 3,
});
this.map = new OlMap({
target: 'map',
layers: [this.layer],
view: this.view,
});
}
组件.html:
<mat-horizontal-stepper
linear
labelPosition="bottom"
#stepper
class="sell-form-container"
>
<mat-step ...>
<form ...>
...
<div id="map"></div> //<- here it does not work, map does not display
...
</form>
</mat-step>
...
</mat-horizontal-stepper>
<div id="map"></div> //<- here it works, map displays
组件.css:
#map {
width: 100%;
height: 500px;
}
我的代码有什么问题?
最佳答案
我认为您的问题与您尝试将 OLMap 附加到 mat-stepper 或 mat-step 的嵌入内容中的内容有关。
在组件生命周期中,子组件在父组件的 OnInit 阶段还没有准备好。因为您将所需的 div 放在 mat 组件中,所以它被包含在该组件的生命周期中。
解决此问题的一种方法是使用 ngAfterViewInit 生命周期方法。在该方法中使用您的代码应该可以解决此问题。
ngAfterViewInit() {
this.map = new OlMap({
target: 'map',
layers: [this.layer],
view: this.view,
});
}
出于潜在的好奇心,我还想介绍另一种使用组件的方法。留意嵌入的内容,如果你想要的元素在当前组件中,你应该使用 ViewChild 装饰器来选择它。否则,如果它在子组件中,请使用 ContentChild 装饰器。
// html
<mat-horizontal-stepper ...>
<mat-step ...>
<form ...>
...
<div #myMapRef id="map"></div>
...
</form>
</mat-step>
...
</mat-horizontal-stepper>
// parent ts
@ContentChild('myMapRef') // <-- if it's in a child component, your case should use this
@ViewChild('myMapRef') // <-- if it's in this component, your "this is working" would use this
myMap: ElementRef;
ngAfterViewInit() {
console.log(this.myMap); // can get the ID from the ElementRef
}
我强烈建议您实际熟悉组件生命周期的深度。这是我希望在学习 Angular 时早点做的一件事。
关于angular - 开放层 5 | Angular 7 |棱 Angular Material | map 在 Angular Material 垫步进器内不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54722963/
有人查看我的代码说下面的 SQL 查询 (SELECT * FROM...) 显然容易受到攻击。我对此进行了研究,似乎我通过使用参数化查询正确地做到了这一点,但显然我遗漏了一些东西。 app.get(
我使用 Curie 作为基本模型,使用自定义数据集创建了一个微调模型。我正在使用 Azure OpenAI 服务。 该模型正在尝试使用最大可能的 token 生成响应。例如,如果 max_token
我正在尝试将6x15数组(映射)中的随机坐标设置为数字3,但前提是该坐标的值仍为0。我要放置的值为3) 25 int shipnum; 26 int x; 27 28 shipnum = 1;
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
您好,我正在寻找“开放”、“链接”和“多重哈希”算法的伪代码。是的,我花了很多时间在谷歌上搜索,但没能找到好东西。 如果你有分享的链接,我将不胜感激 问候 最佳答案 这hash table tutor
是否可以实现 Visitor Pattern尊重 Open/Closed Principle ,但仍然可以添加新的可访问类? 开放/封闭原则指出“软件实体(类、模块、函数等)应该对扩展开放,但对修改关
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 12 年前
我创建了 Azure 开放 AI 服务我想针对特定问题训练模型。但是,自定义模板按钮被禁用。在文档中,它说明了如何生成包含要训练的问题和答案的 .Jsonl,但没有任何内容可以导入这些文件。有人拿到了
我找到了一些关于开放/封闭递归的解释,但我不明白为什么定义中包含“递归”一词,或者它与动态/静态调度相比如何。我找到的解释中有: Open recursion. Another handy featu
我正在尝试为在加权图上运行的库找出类设计。可以在这个图上执行各种算法,例如,找到两个节点之间的最短距离,两个节点之间的最长距离,两个节点之间距离小于 10 的路径数(比方说)等。 我关心的不是我所知道
谁能告诉我开放 SSL 和安全 SSL 之间的区别。 我已经在 Play 商店发布了新的 Android 应用程序,它使用远程 API。 在 API 服务器上,我已经成功安装了安全 SSL。但我仍然被
当我将 url 加载到 WebView 并尝试打开链接时,其中一些会显示如下错误页面: net::ERR_UNKNOWN_URL_SCHEME intent://maps.yandex.ru?utm_
2 月 24 日消息 据外媒 TheVerge 报道,2 月 23 日晚间,LG 宣布将该公司的 webOS 智能电视平台授权给其他电视厂商使用,目前 LG 已和 RCA、Ayonz 和康佳等电视厂
我一直在思考这个面向对象的设计问题,但无法提出令人满意的解决方案,所以我想在这里向人群开放以征求意见。 我有一个代表回合制棋盘游戏的 Game 类,出于这个问题的目的,我们可以假设它类似于 Monop
我们有一个 Web 服务,它充当我们的客户和另一个服务之间的网关。客户端向第三方服务发送消息并从其接收随机消息。客户端的服务器通过安全套接字打开到我们的 Web 服务器的 channel ,以便接收传
应用商店里有一个叫 Touchpad 的应用,最后一次更新是在 11 月 29 日,其中包含一个新功能,支持“使用设备键盘上的 Siri 键向电脑发送文本”,我想知道是否有开放的 API Siri现在
我尝试在认知搜索上下文中为 Azure 开放 AI 服务添加矢量搜索时遇到问题。选择勾选标记后,即使有可用的现有文本嵌入模型,我也无法列出任何模型。造成这种差异的可能原因是什么以及如何解决? 最佳答案
我尝试在认知搜索上下文中为 Azure 开放 AI 服务添加矢量搜索时遇到问题。选择勾选标记后,即使有可用的现有文本嵌入模型,我也无法列出任何模型。造成这种差异的可能原因是什么以及如何解决? 最佳答案
我们的堆栈:Tomcat 7、Spring 3.1.1、OpenJPA 2.2.0 我遇到了一个问题,根源是比较: server1.equals(server2); server1 和 server2
我正在使用以下命令设置一个 java EE 项目(打开)JPA。我使用 glassfish 4.0 作为我的应用程序服务器,但似乎无法让持久性发挥作用。 我面临的问题似乎是一个相当普遍的问题,因为同一
我是一名优秀的程序员,十分优秀!