Доброго дня-утра-вечера
Начал копать Angular2 и вот завис:
Не получается сделать сервис. Такое впечатление, что он не отрабатывает вообще
Помогите пжалста, кто не сильно занят...
//app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { Settings} from './settings';
import { CurrentLocationService } from './current-location.service';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { GeolocationComponent } from './geolocation/geolocation.component';
import { GetweatherService } from './getweather.service';
import { GetcityComponent } from './getcity/getcity.component';
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
GeolocationComponent,
GetcityComponent
],
imports: [
BrowserModule, HttpModule
],
providers: [GetweatherService,CurrentLocationService],
bootstrap: [AppComponent]
})
export class AppModule { }
//current-location.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class CurrentLocationService {
mylocation = {};
CurrentPosition() {
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(this.setP osition.bind(this));
};
console.log('ок'); // ВОТ этого в логах нет...
}
private setPosition(position){
this.mylocation = position.coords;
}
}
вызываю сервис например здесь
//geolocation.components.ts
import { Component, Input, OnInit } from '@angular/core';
import { CurrentLocationService } from '../current-location.service';
@Component({
selector: 'app-geolocation',
templateUrl: './geolocation.component.html',
styleUrls: ['./geolocation.component.scss'],
})
export class GeolocationComponent implements OnInit {
constructor(private _currentlocationservice: CurrentLocationService) {}
ngOnInit() {
var location = this._currentlocationservice.mylocation;
}
}