그래서 나는 이 프로그램에서는 각도가 지금까지 나는 우편 번호에서 사용자와 버튼을 클릭에 보내는 입력하는 함수가 전송하는 api 로 변환 Lat&좌표. 아래를 참조하십시오:
home.component.html
<div class="center" style="margin-top:50px;">
<label for="ZipCode"><b>Zip Code</b></label>
</div>
<div class="center">
<input name="zipcode" #zipcode id="zipcode" type="text" placeholder="Enter Zip Code" maxlength="5">
</div>
<div class="center" style="margin-top:100px;">
<button class="button button1" (click)="getCoords(zipcode.value)" ><b>Retrieve Data</b></button>
</div>
명확하게 이것은 단지 조각의 코드 하지만 충분히 화면에 표시됩니다. 다음은 기능을 가진 api 고 그런 다음 보기소 구성요소/페이지:
다.구성 요소입니다.ts
export class HomeComponent implements OnInit {
constructor(
private router: Router
){}
ngOnInit(): void {
}
getCoords(val: any){
var url = "http://www.mapquestapi.com/geocoding/v1/address?key=MYKEY&location=" + val;
fetch(url)
.then((res) => res.json())
.then((data) => {
var lat = data.results[0].locations[0].displayLatLng.lat;
var long = data.results[0].locations[0].displayLatLng.lng;
this.router.navigate(["/stations"])
})
}
}
다.구성 요소입니다.ts -당신이 볼 수 있듯이 아무것도 여기에 있기 때문에 아직 내가 무엇을 할
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'app-stations',
templateUrl: './stations.component.html'
})
export class StationsComponent implements OnInit {
ngOnInit(): void {
}
}
이제 이 모든 제대로 작동합니다. 내가 테스트 lat 및 장에서 변수를 콘솔 로그를 반환합니다 lat 및 장됩니다. 나의 문제는 나를 보내야 lat 및 장 값을 다른 구성 요소/페이지를 사용합니다. 나는 거짓말을 말해서 저는 인터넷 방법을 찾기 위해 노력하고 그렇게 하지만 분명히 그것은 밤에서 쉽 모니다. 사람이 어떤 아이디어에 전달하 lat 및 장 값을 다른 구성 요소/페이지?
dataLat: lat
과 오류를 말한다:Argument of type '{ dataLat: any; dataLong: any; }' is not assignable to parameter of type 'NavigationExtras'. Object literal may only specify known properties, and 'dataLat' does not exist in type 'NavigationExtras'.