2015-11-30 77 views
0

我的模態代碼在這裏離子模態參數不工作

$ionicModal.fromTemplateUrl('my-modal.html', { 
    scope: $scope, 
    animation: 'slide-in-up' 
    }).then(function(modal) { 
    $scope.modal = modal; 
    });  

我的按鈕和功能代碼這裏(在模式按鈕)

<button class="button button-icon ion-ios-star-outline rate" ng-repeat='i in rate_num' ng-click='rateStar(i)'></button>//rate_num = [1,2,3,4,5]; 

$scope.rateStar = function(n){ 
     console.log(n); 
     $rootScope.rate = n; 
    }; 

它工作正常不帶模式。 butin模式它不工作。

當我點擊那個按鈕我想要console.log(數字); 前)當我點擊第一個按鈕,我想CONSOLE.LOG(1)後,單擊第二個 - >執行console.log(2)..等等

,但現在,代碼只運行CONSOLE.LOG(1 ) - >只有第一個元素叫...哪裏錯了...?

回答

0

試試這個:

的index.html:

<body ng-app="starter"> 
    <ion-pane> 
     <ion-header-bar class="bar-stable"> 
     <h1 class="title">Ionic Blank Starter</h1> 
     </ion-header-bar> 
     <ion-content ng-controller="ModalDemoController"> 
     <button ng-click="showModal()">Show</button> 
     </ion-content> 
    </ion-pane> 
    </body> 
    <script id="my-modal.html" type="text/ng-template"> 
    <ion-modal-view> 
    <ion-header-bar class="dark"> 
     <h1 class="title">Modal Demo</h1> 
     <button class="button button-clear ion-close" ng-click="closeModal()"></button> 
    </ion-header-bar> 
    <ion-content class="content-stable"> 
     <button ng-repeat='i in rate_num' class="button button-icon ion-ios-star-outline rate" ng-click='rateStar(i)'> {{i}}</button> 
     </ion-content> 
    </ion-modal-view> 
</script> 

和控制器:

.controller('ModalDemoController', function($scope,$ionicModal) { 

    $ionicModal.fromTemplateUrl('my-modal.html', { 
     scope: $scope, 
     animation: 'slide-in-up' 
    }).then(function(modal) { 
     $scope.modal = modal; 
    }); 
    $scope.rate_num = [1,2,3,4,5]; 
    $scope.showModal = function() { 
     $scope.modal.show(); 
    }; 

    $scope.closeModal = function() { 
     $scope.modal.hide(); 
    };  
    $scope.rateStar = function(n){ 
     console.log(n); 
     $scope.rate = n; 
    }; 
}); 

希望這會幫助你。

+0

真是個好人,謝謝! – Yoohogyun

+0

夥計們,我有一個問題。爲什麼我的代碼不起作用,並且你的代碼有效?你能解釋一下嗎? – Yoohogyun