【发布时间】:2021-02-19 15:58:43
【问题描述】:
我想设置一个带有多个 arg 的 url。我试试这个但不工作:
@Injectable()
export class MapService {
ign : string = 'https://wxs.ign.fr/secret/geoportail/wmts?';
ignEnd = '&tilematrixset=PM&tilematrix={z}&tilecol={x}&tilerow={y}';
ignSat = this.ign + 'layer=ORTHOIMAGERY.ORTHOPHOTOS';
this.ignSat = this.ignSat + '&tilematrixset=PM';
this.ignSat = this.ignSat + '&Service=WMTS';
this.ignSat = this.ignSat + '&Request=GetTile';
this.ignSat = this.ignSat + '&Version=1.0.0';
this.ignSat = this.ignSat + '&Format=image%2Fjpeg' + this.ignEnd;
private LAYER_IGN_SATELLITE = {
id: 'ignsatelite',
name: 'IGN Satelite',
enabled: false,
layer: tileLayer(this.ignSat, {
maxZoom: 20,
attribution: 'IGN'
})
};
...
constructor() {}
...
}
我有这个错误:
Unexpected token. A constructor, method, accessor, or property was expected.ts(1068)
编辑
我试试这个:
ignSat = ignSat + '&style=normal';
我试试这个:
ignSat = this.ignSat.concat('&style=normal');
我试试这个:
this.ignSat = this.ignSat.concat('&style=normal');
【问题讨论】:
-
我假设前 3 行末尾需要一个分号
-
this.ign在哪里定义?你的意思是ign? -
请考虑修改此问题中的代码,以便构成一个适合放入独立 IDE 的 minimal reproducible example,例如 The TypeScript Playground,它演示了您看到的问题并且没有不相关的错误。这将允许其他想要帮助您开始解决问题的人,而无需他们首先致力于重现问题。
-
请考虑查看How to Ask 的指南,尤其是minimal reproducible example 的构成要素。您应该能够提供代码,将其粘贴到独立 IDE 中时,实际演示您所看到的错误。当我将您的代码粘贴到我的 IDE 中时,我得到了很多错误,但没有一个是您提到的错误。如果您无法提供minimal reproducible example,那么您需要开始描述确切您看到错误的位置,以及准确您正在编码的环境,以便其他人倾向于进行远程 IT 支持可能会有所帮助。祝你好运!
-
您需要将所有这些都放在构造函数中,请参阅TypeScript: Handbook - Classes。
标签: angular typescript