【发布时间】:2016-05-24 21:46:32
【问题描述】:
我需要一个动态弹出窗口,其中图像在单击时会改变其不透明度。它完美地工作,但只有当弹出窗口超出功能时。我需要它在一个函数中。 这是我的控制器:
$scope.imgIds = ['0', '1', '2', '3', '4', '5'];
$scope.selectedImg = '-1';
$scope.itemClicked = function(index){
console.log(index);
$scope.selectedImg = index;
}
/*$ionicPopup.prompt({
title: 'Como foi seu treino?',
scope: $scope,
templateUrl: 'templates/icons.html'
});*/
//Envia Mensagem do Treino
$scope.sendMessage = function(tempo,id_serie) {
$ionicPopup.prompt({
title: 'Como foi seu treino?',
scope: $scope,
templateUrl: 'templates/icons.html'
}).then(function(res) {
$http({
url: $localStorage.url+'/serie/mensagem',
method: 'POST',
data: {id_serie : id_serie, mensagem :res, tempo: tempo, datahora: $scope.getData()},
headers : {'Content-Type':'application/json; charset=UTF-8'}
});
});
}
//Finaliza Treino
$scope.finalizar = function() {
document.getElementById('timer').getElementsByTagName('timer')[0].stop();
document.getElementById('play').className = 'button icon button-balanced button-block ion-play col';
var tempo = document.getElementById('timer').getElementsByTagName('timer')[0].innerText;
var confirmPopup = $ionicPopup.confirm({
title: 'Atenção',
template: 'Tempo: '+tempo+'<br>Finalizar Treino?',
buttons: [
{ text: 'Cancelar', onTap: function(e) { return false; }},
{ text: '<b>Ok</b>',
type: 'button-positive',
onTap: function(e) {
document.getElementById('timer').getElementsByTagName('timer')[0].start();
document.getElementById('timer').getElementsByTagName('timer')[0].stop();
$state.go('tab.series', {});
$scope.sendMessage(tempo,$scope.id_serie);
}
},
]
});
}
这是icons.html:
<style>
.selected {opacity:1;margin:auto;}
.unselected {opacity:0.5;margin:auto;}
</style>
<div class='row'>
<img ng-repeat="imgId in imgIds" src="img/{{imgId}}.png" width="30" height="30"
ng-class="{'selected':{{imgId}}==selectedImg,'unselected':{{imgId}}!=selectedImg}" ng-click="itemClicked(imgId)"/>
</div>
Algum Comentário?<br>
<input type="text"/>
控制台没有错误。但是图像不会改变 css,弹出窗口被锁定并且按钮什么也不做。
【问题讨论】:
-
我认为我们需要查看更多您的代码。你能提供一个Minimal, Complete and Verifiable Example 的错误吗? (Plunkr 什么的)
-
用你的答案制作了一个实时代码,它似乎工作正常。 play.ionic.io/app/a1e1734a04f6 。也许可以成为您的 Ionic 版本?
-
确实,代码是一样的,它正在工作。我会看看。谢谢Italo。
-
我还是不成功。完整的代码现在在那里。我不明白为什么弹出窗口会锁定应用程序。
-
我看到有 2 个不同的范围。在函数内部,它出现在控制台中的范围内。在外面,它出现了 ChildScope。
标签: angularjs scope ionic-framework popup