离子模态参数不起作用
Ionic Modal Parameter not working
我的模态代码在这里
$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;
};
它在没有模态的情况下工作正常。
但在模式中它不起作用。
当我点击那个按钮时我想 console.log(Number);
例如)当我点击第一个按钮时,我想 console.log(1),点击第二个按钮后 -> console.log(2).. 等等
但现在代码 运行 仅 console.log(1) -> 仅调用第一个元素...哪里错了...?
试试这个:
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;
};
});
希望对您有所帮助。
我的模态代码在这里
$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;
};
它在没有模态的情况下工作正常。 但在模式中它不起作用。
当我点击那个按钮时我想 console.log(Number); 例如)当我点击第一个按钮时,我想 console.log(1),点击第二个按钮后 -> console.log(2).. 等等
但现在代码 运行 仅 console.log(1) -> 仅调用第一个元素...哪里错了...?
试试这个:
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;
};
});
希望对您有所帮助。