を見る:
$scope.$watch('infos.location', function(newValue, oldValue) {
if (newValue.formatted_address == 'Erreur ...') {
var confirmPopup = $ionicPopup.confirm({
title: 'Geolocalisation',
template: 'Voulez-vous activer la géolocalisation ?'
});
confirmPopup.then(function(res) {
if (res) {
$cordovaPreferences.show().success(function(value) {
//alert("Success: " + value);
}).error(function(error) {
// alert("Error: " + error);
})
} else {
console.log('You are not sure');
}
});
}
}, true);
それは、この入力を見る:
<label class="item item-input">*
<ion-google-place placeholder="Veuillez saisir l'adresse du bien" ng-model="infos.location" current-location="true"/>
</label>
しかし、私は私の見解を開いたとき、私はこのエラーがあります:
Error: undefined is not an object (evaluating 'newValue.formatted_address')
どうすればこのkを回避できますかエラーインディー?この値 'Erreur ...'を見て、confirmPopupを呼び出すより良い解決策がありますか?ありがとうございます。
このコードから 'infos.location'はどのように' .formatted_address'プロパティを取得しますか? – Claies
これは '' ion-google-place "'ディレクティブから来ます。それは入力です、あなたはそれをクリックして、あなたはあなたのジオロケーション/フォーマットアドレスと他のものを持っています:https://github.com/israelidanny/ion-google-place –
あなたは本当にこのようにすることはできません、と私は思います。そのコードには約束があり、約束が返された後に 'ng-model'が変更されています。あなたの '$ watch'は、入力がユーザによって変更されるたびに少なくとも2回、あるいはそれ以上になることがあります。あなたは 'if(newValue.formatted_address){'のようなガード・ステートメントを置くことができますが、これはパフォーマンスの問題を引き起こす可能性があります。 – Claies