Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript Can';t绑定到';单张选项';因为它不是';t'的已知属性;分区';_Typescript_Ngx Leaflet - Fatal编程技术网

Typescript Can';t绑定到';单张选项';因为它不是';t'的已知属性;分区';

Typescript Can';t绑定到';单张选项';因为它不是';t'的已知属性;分区';,typescript,ngx-leaflet,Typescript,Ngx Leaflet,我知道这是一个经常出现的问题,通过修改导入语句可以解决。我现在有 import { LeafletModule } from 'node_modules/@asymmetrik/ngx-leaflet'; import * as L from 'leaflet'; import { } from '@types/leaflet'; 我引用的是选项,因此: options = { layers: [ this.googleHybrid ], zoom: 1

我知道这是一个经常出现的问题,通过修改导入语句可以解决。我现在有

import { LeafletModule } from 'node_modules/@asymmetrik/ngx-leaflet';
import * as L from 'leaflet';
import { } from '@types/leaflet';
我引用的是选项,因此:

options = {
    layers: [
        this.googleHybrid
    ],
    zoom: 1.49,
    zoomSnap: 0,
    center: L.latLng([180, -180])}
我觉得我遇到这个问题是因为我把传单上的所有东西都导入了L。有什么想法吗


编辑:我还应该补充一点,这只是在测试中才会出现。

如果Angular.io没有将模块正确加载到应用程序中,就会出现这种情况。通常,您会执行以下操作:

首先,将
模块
导入应用程序模块:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    LeafletModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
然后,如果您在应用程序模块的子模块中使用ngx传单,您也需要将其导入该子模块:

import { NgModule } from '@angular/core';
import { LeafletModule } from '@asymmetrik/ngx-leaflet';

@NgModule({
  declarations: [
  ],
  imports: [
    LeafletModule
  ],
  providers: []
})
export class MyModule { }
有关于如何使用Angular CLI启动和运行的说明,但没有说明使用ngx传单的应用程序模块的子模块的情况

还有几点需要注意:

  • 导入
    模块
    时,您通常需要提供进入节点模块的路径。大多数构建管道将自动取消对包的引用
  • @types/传单
    导入也是如此。如果需要,大多数构建管道将自动拉入类型信息
  • 从“传单”中导入*作为L是完全有效的您还可以根据需要导入特定项目,例如,
    从{传单}导入地图

    • 我把它修好了。我没有将正确的导入添加到父组件的测试配置文件中。现在一切都好了

      我的测试也有同样的问题, 但当我补充说:

      imports: [
        LeafletModule,
        LeafletMarkerClusterModule
      ]
      

      问题消失了。

      我刚刚确认我做了所有这些,出于某种原因,我仍然会收到错误。我很感激这些笔记,因为它们也很有帮助。我还应该指出一个事实,这只是在测试中才会出现。刚刚编辑了我的帖子。在
      ngx-leaflet@7
      ,已删除
      forRoot()
      。另外,请确保模块配置正确,我在尝试将模块放在另一个文件夹中时出错。您可以添加测试中缺少的部分吗?我也遇到了同样的问题