Javascript 使用coffeescript自动完成放置后,无法从getPlace获取值
我是angularJs/coffeescript的新手,正在尝试将其与谷歌地图集成 目标是在使用getPlace()自动完成后获取place_id,并通过将其传递给服务方法将其存储在安全的地方,以便以后保存 这是密码 咖啡代码Javascript 使用coffeescript自动完成放置后,无法从getPlace获取值,javascript,jquery,angularjs,google-maps,coffeescript,Javascript,Jquery,Angularjs,Google Maps,Coffeescript,我是angularJs/coffeescript的新手,正在尝试将其与谷歌地图集成 目标是在使用getPlace()自动完成后获取place_id,并通过将其传递给服务方法将其存储在安全的地方,以便以后保存 这是密码 咖啡代码 class SomeController constructor: (@$scope, @$log, @$location, @SomeService) -> @listing = {} getPlace: (place) ->
class SomeController
constructor: (@$scope, @$log, @$location, @SomeService) ->
@listing = {}
getPlace: (place) ->
place = @getPlace()
alert(place.place_id)
return place
doSomethingMore: () ->
@variable.whereGeo = @getPlace().place_id
alert(@listing.whereGeo)
@SomeService.someFunction(@listing) //save the place id somewhere
controllersModule.controller('SomeController', SomeController)
HTML
理想情况下,在自动完成后,此处应该出现一些内容
place_id={{sc.place}}
提交
现在使用的模块是ngMap。这里是链接
现在让我补充细节和问题
非常感谢您对此提供的任何帮助。提前谢谢。好的。。所以我做错了。经过一些研究发现了这一点。我把望远镜全弄错了。最后解释一下 咖啡脚本
class SomeController
constructor: (@$scope, @$log, @$location, @SomeService) ->
@listing = {}
@place
autocomplete_options = {
types: ['geocode']
}
autocomplete = new google.maps.places.Autocomplete(document.getElementById('where'), autocomplete_options)
google.maps.event.addListener autocomplete, 'place_changed', =>
place = autocomplete.getPlace()
console.log(place.place_id)
@$scope.$apply =>
@$scope.place = place.place_id
doSomethingMore: () ->
@liating.whereGeo = @$scope.place // now place id is available in scope
alert(@listing.whereGeo)
@SomeService.someFunction(@listing) //save the place id somewhere
controllersModule.controller('SomeController', SomeController)
HTML
提交
解释
好的。。所以我做错了。经过一些研究发现了这一点。我把望远镜全弄错了。最后解释一下 咖啡脚本
class SomeController
constructor: (@$scope, @$log, @$location, @SomeService) ->
@listing = {}
@place
autocomplete_options = {
types: ['geocode']
}
autocomplete = new google.maps.places.Autocomplete(document.getElementById('where'), autocomplete_options)
google.maps.event.addListener autocomplete, 'place_changed', =>
place = autocomplete.getPlace()
console.log(place.place_id)
@$scope.$apply =>
@$scope.place = place.place_id
doSomethingMore: () ->
@liating.whereGeo = @$scope.place // now place id is available in scope
alert(@listing.whereGeo)
@SomeService.someFunction(@listing) //save the place id somewhere
controllersModule.controller('SomeController', SomeController)
HTML
提交
解释
<div ng-controller="SomeController as sc">
<div class="col-sm-3">
<input type="text" class="form-control" name="where" id="where" placeholder=""
ng-model="sc.search.where">
</div>
<div class="col-sm-offset-4 col-sm-2 col-xs-1 text-right">
<button ng-click="sc.doSomethingMore()" class="btn btn-success btn-lg" id="btn_create">Submit</button>
</div>
</div>