2016-07-27 5 views
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 콜백 –

+0

@ PankajParkar, 팁 주셔서 감사합니다. 두 개 이상의 토글 스위치가 있고 기본적으로 하나는 자동으로 켜지고 다른 하나가 켜지면 첫 번째 스위치를 끄는 방법 – neiza

답변

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> 
1

귀하의 코드는 모든 HTTP 안에 시도, 그것은 외부해야한다 : 모든 코드는`$ http.get` 성공 내부에 랩 이유

.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

덕분에 효과가있었습니다. 두 개 이상의 토글 스위치가 있고 기본적으로 하나가 자동으로 켜지고 다른 하나가 켜지면 첫 번째 스위치를 끄면 어떨지 알 수있는 기능 안에서 – neiza

+0

을 끄면 $ scope .pushNotificationSecond = {checked : false}; 두 번째 스위치 인 pushNotificationSecond =) –

관련 문제