我的模态代码
$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 modal它没有用。
当我点击那个按钮我想要console.log(Number); ex)当我点击第一个按钮,我想要console.log(1),点击第二个 - &gt; console.log(2)..等等
但现在该代码只运行console.log(1) - &gt;只有第一个元素叫做......哪里错了......?
答案 0 :(得分: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;
};
});
希望这会对你有所帮助。