저는 google-places 지시문을 사용하고 있지만 모든 사항이 정상 이었지만 갑자기 변수 $ scope.location이 컨트롤러에 정의되어 있지 않습니다. 그러나보기에서 그것은 사용할 수 있습니까?
무엇이 잘못 되었나요? 보기에서 감사
yuppiApp.directive('googlePlaces', function(){
return {
restrict:'E',
replace:true,
scope: {location:'='},
template: "<input id='google_places_ac' ng-model='google_map' name='map' type='text' required/>",
link: function($scope, elm, attrs){
var autocomplete = new google.maps.places.Autocomplete($("#google_places_ac")[0], {});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
$scope.location = place.geometry.location.lat() + ',' + place.geometry.location.lng();
console.log($scope.location);
$scope.$apply();
});
}
}
});
코드 : 컨트롤러에서
{{ location }}
<google-places location="location"></google-places>
코드 : 내가 지시와 컨트롤러 두 경우 모두 CONSOLE.LOG ($ 범위)라고
$scope.addNew = function() {
console.log("Location: " + $scope.location);
};
는과 보인다 거기에 $ 범위의 두 가지 버전이 있습니다. 나는 왜 그런지 이해하지 못한다.
Object { $id: "0U8", $$childTail: null, $$childHead: null, .......
Object { $id: "00M", this: Object, $$listeners: Object
$ scope.location을 다른 곳에서 만들거나 할당하지 않으시겠습니까? –
버튼 클릭을 호출하는 컨트롤러 기능에서 사용하고 있습니다. 전에는 작동하지만 정확히 무엇이 바뀌 었는지는 알 수 없습니다. 나는 아직 완전히 새로운 것은 아니지만 완전히 새로운 것이다. –
양방향 바인딩을 사용하지 않을 때 왜'location = "location"'을해야합니까? – PSL