ng-点击即使它在同一范围内也不会触发

时间:2016-11-06 21:23:25

标签: javascript angularjs

我搜索了论坛,但我没有找到这个问题的答案。我想在按钮点击后将输入字段的值设置为地理定位地址,但是ng-Click =" locate()"没有开火。这是我的HTML:

<script id="templates/search.html" type="text/ng-template">
    <ion-view view-title="Datenerfassung">
      <ion-content class="padding" ng-controller="DataCtrl">
        <div class="list">

          <!-- Adressen Input Feld -->
           <label class="item item-input item-floating-label">
             <span class="input-label">Startpunkt in Adressform</span>
             <input id="address" type="text" placeholder="Startpunkt in Adressform">
             <button id="curr_loc" class="button button-balanced" ng-Click="locate()">this-one-doesnt-fire</button>
           </label>

           <!-- Zeit Input Feld -->
           <label class="item item-input item-floating-label">
             <span class="input-label">Zeit in Minuten</span>
             <input id="time" type="number" placeholder="Zeit in Minuten">
           </label>
        </div>
        <!-- Fortbewegungsmittel Toggle Liste -->
        <div class="item item-divider">
          Mit welchem Fortbewegungsmittel </br>
          möchten Sie die Umgebung erkunden?
        </div>

        <ion-radio ng-model="$parent.move" value="walk">Zu Fuß</ion-radio>
        <ion-radio ng-model="$parent.move" value="transit">Tram</ion-radio>
        <ion-radio ng-model="$parent.move" value="car">Auto</ion-radio>
        <ion-radio ng-model="$parent.move" value="bike">Fahrrad</ion-radio>

        <!-- Button zum loslegen -->
        <button id="erkunden" ui-sref="map" class="button button-balanced" ng-Click="setData()">Erkunden</button>
      </ion-content>
      <ion-tabs class="tabs-balanced tabs-icon-top">
    <ion-tab ui-sref="home" title="Home" icon="ion-home"></ion-tab>
    <ion-tab ui-sref="faq" title="FAQ" icon="ion-help-circled"></ion-tab>
    <ion-tab ui-sref="about" title="About" icon="ion-information-circled"></ion-tab>
    <ion-tab ui-sref="impressum" title="Impressum" icon="ion-clipboard"></ion-tab>
  </ion-tabs>
    </ion-view>
 </script>

我的控制器看起来像这样:

mapApp.controller("DataCtrl", function($scope, dataService) {
  $scope.setData = function() {
    var address = document.getElementById("address").value;
    var time = document.getElementById("time").value;
    var move = $scope.move;
    dataService.setData(address,time,move);
  };

  $scope.locate = function() {
    console.log("asd");
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };
            console.log(pos);
            document.getElementById("address").value = pos[0] + "," + pos[1];
        });
    }
  };
});

就像我说的,单击按钮不会触发locate()函数。否则,点击&#34; Erkunden&#34;按钮触发scope.setData()函数,即使两个按钮定义相似。

很确定这是我在隧道视觉中看不到的一些愚蠢错误,但我无法解决这个问题。

感谢您提前帮助,致以最诚挚的问候 巨乐

2 个答案:

答案 0 :(得分:2)

如果您按下标签范围之外的按钮,您的代码将完美运行。

<label class="item item-input item-floating-label">
  <span class="input-label">Startpunkt in Adressform</span>
  <input id="address" type="text" placeholder="Startpunkt in Adressform">
</label>
<button id="curr_loc" class="button button-balanced" ng-click="locate()">this-one-doesnt-fire</button>

答案 1 :(得分:0)

您的AngularJS指令拼写错误为&#39; ng-Click&#39;。正确的拼写是点击&#39;