Показать сообщение отдельно
  #3 (permalink)  
Старый 08.09.2017, 11:48
Интересующийся
Отправить личное сообщение для mrmammoth Посмотреть профиль Найти все сообщения от mrmammoth
 
Регистрация: 19.03.2014
Сообщений: 22

Спасибо, помогло.
Ещё не поможете малость?
//geolocation.component.ts
import { Component, Input, OnInit } from '@angular/core';
import { GetlocationService } from '../getlocation.service';

@Component({
  selector: 'app-geolocation',
  templateUrl: './geolocation.component.html',
  styleUrls: ['./geolocation.component.scss'],
  
})
export class GeolocationComponent implements OnInit {

  constructor( private _getlocationservice: GetlocationService) { }

  myLocation={};

  ngOnInit() {
    this._getlocationservice.getCurrentPosition().subscribe(
     data => {this.myLocation = data}, 
     error => console.log('Error fetching data'));
    console.log(this.myLocation)
  }

}

//geolocation.component.html
<p>{{myLocation.coords.latitude}} , {{myLocation.coords.longitude}}</p>

Координаты на странице отображаются, но в лог вываливает вот такое:
ERROR TypeError: _co.myLocation.coords is undefined
Stack trace:
View_GeolocationComponent_0/<@ng:///AppModule/GeolocationComponent.ngfactory.js:11:9
updateRenderer@http://localhost:4200/vendor.bundle.js:56763:61
checkAndUpdateView@http://localhost:...ndor.bundle.js:56282:5
callViewAction@http://localhost:4200/vendor.bundle.js:56642:21
execComponentViewsAction@http://loca...ndor.bundle.js:56574:13
checkAndUpdateView@http://localhost:...ndor.bundle.js:56283:5
callViewAction@http://localhost:4200/vendor.bundle.js:56642:21
execComponentViewsAction@http://loca...ndor.bundle.js:56574:13
checkAndUpdateView@http://localhost:...ndor.bundle.js:56283:5
callViewAction@http://localhost:4200/vendor.bundle.js:56642:21
execComponentViewsAction@http://loca...ndor.bundle.js:56574:13
checkAndUpdateView@http://localhost:...ndor.bundle.js:56283:5
../../../core/@angular/core.es5.js/</ViewRef_.prototype.detectChanges@http://localhost:4200/vendor.bundle.js:54203:9
../../../core/@angular/core.es5.js/</ApplicationRef_.prototype.tick/<@http://localhost:4200/vendor.bundle.js:48834:58
../../../core/@angular/core.es5.js/</ApplicationRef_.prototype.tick@http://localhost:4200/vendor.bundle.js:48834:13
../../../core/@angular/core.es5.js/</ApplicationRef_.prototype._loadComponent@http://localhost:4200/vendor.bundle.js:48809:9
../../../core/@angular/core.es5.js/</ApplicationRef_.prototype.bootstrap@http://localhost:4200/vendor.bundle.js:48797:9
../../../core/@angular/core.es5.js/</PlatformRef_.prototype._moduleDoBootstrap/<@http://localhost:4200/vendor.bundle.js:48568:74
../../../core/@angular/core.es5.js/</PlatformRef_.prototype._moduleDoBootstrap@http://localhost:4200/vendor.bundle.js:48568:13
../../../core/@angular/core.es5.js/</PlatformRef_.prototype._bootstrapModuleFactoryWith Zone/</</<@http://localhost:4200/vendor.bundle.js:48530:21
../../../../zone.js/dist/zone.js/</</ZoneDelegate.prototype.invoke@http://localhost:4200/polyfills.bundle.js:2937:17
onInvoke@http://localhost:4200/vendor.bundle.js:47912:24
../../../../zone.js/dist/zone.js/</</ZoneDelegate.prototype.invoke@http://localhost:4200/polyfills.bundle.js:2936:17
../../../../zone.js/dist/zone.js/</</Zone.prototype.run@http://localhost:4200/polyfills.bundle.js:2687:24
scheduleResolveOrReject/<@http://localhost:4200/polyfills.bundle.js:3389:52
../../../../zone.js/dist/zone.js/</</ZoneDelegate.prototype.invokeTask@http://localhost:4200/polyfills.bundle.js:2970:17
onInvokeTask@http://localhost:4200/vendor.bundle.js:47903:24
../../../../zone.js/dist/zone.js/</</ZoneDelegate.prototype.invokeTask@http://localhost:4200/polyfills.bundle.js:2969:17
../../../../zone.js/dist/zone.js/</</Zone.prototype.runTask@http://localhost:4200/polyfills.bundle.js:2737:28
drainMicroTaskQueue@http://localhost...ills.bundle.js:3147:25

в чём беда?
Ответить с цитированием