оповещение при переключении

0

Я хочу показать предупреждение, когда переключатель включен и выключен, но ему трудно. Я следовал этому руководству, но мой не работает так, как должен

http://codepen.io/rossmartin/pen/iwuvC

JS

.controller('shops',['$scope','$http','$timeout',function($scope,$http,$timeout){
  $http.get('http://localhost/site/templates/shop.php').success(function(data){
    $scope.shops=data ;   
    $scope.pushNotificationChange = function() {
    $timeout(function() {
      alert('Push Notification Change: '+ $scope.pushNotification.checked);
    }, 0);
  };
  $scope.pushNotification = { checked: true };
  });
}])

HTML

<ion-view  align-title="center">
  <ion-content overflow-scroll="false" has-bouncing="true" class=padding>
  <ion-list>
    <div ng-controller="shops" ng-repeat="item in shops">
      <ion-item class="item-thumbnail-left item-text-wrap"> 
        <img src="img/index/fashion.png" alt="photo" width="32" height="32" />
        <h2>{{item.shop_name}} </h2>
        <p>{{item.biz_location}}</p>
        <div align="right">
          <label class="toggle toggle-balanced">
          <input type="checkbox"ng-model="pushNotification.checked"
                    ng-change="pushNotificationChange()">
            <div class="track"><div class="handle"></div></div>
          </label>
        </div> 
      </ion-item>
    </div>   
  </ion-list> 
  </ion-content overflow-scroll="false" has-bouncing="true">        
</ion-view>

любая помощь в том, как сделать эту работу?

  • 1
    почему весь код обернут в успех $http.get , он должен быть за пределами обратного вызова $ http
  • 0
    @PankajParkar, спасибо за совет. Предположим, что есть два или более тумблера, и по умолчанию один включается автоматически, а когда другой включен, как сделать первый выключить
Теги:
ionic-framework

2 ответа

1

Ваш код находится внутри http, он должен быть снаружи:

.controller('shops',['$scope','$http','$timeout',function($scope,$http,$timeout){
  $http.get('http://localhost/site/templates/shop.php').success(function(data){
     $scope.shops=data;   
  });

  $scope.pushNotificationChange = function() {
    $timeout(function() {
      alert('Push Notification Change: '+   $scope.pushNotification.checked);
    }, 0);
  };
  $scope.pushNotification = { checked: true };    
}])
  • 0
    спасибо, это сработало. Предположим, что есть два или более тумблера, и по умолчанию один включается автоматически, а когда другой включен, как сделать первый выключить
  • 0
    внутри функции, где у вас есть предупреждение, вы должны сделать что-то вроде этого, $ scope.pushNotificationSecond = {checked: false}; pushNotificationSecond - второй переключатель =)
0

попробуй это

<ion-view  align-title="center">
  <ion-content overflow-scroll="false" has-bouncing="true" class=padding>
  <ion-list>
   <div ng-controller="shops">
    <div ng-repeat="item in shops">
      <ion-item class="item-thumbnail-left item-text-wrap"> 
        <img src="img/index/fashion.png" alt="photo" width="32" height="32" />
        <h2>{{item.shop_name}} </h2>
        <p>{{item.biz_location}}</p>
        <div align="right">
          <label class="toggle toggle-balanced">
          <input type="checkbox"ng-model="pushNotification.checked"
                    ng-change="pushNotificationChange()">
            <div class="track"><div class="handle"></div></div>
          </label>
        </div> 
      </ion-item>
    </div>
    </div> 
  </ion-list> 
  </ion-content overflow-scroll="false" has-bouncing="true">        
</ion-view>

Ещё вопросы

Сообщество Overcoder
Наверх
Меню