【发布时间】:2016-03-16 06:40:13
【问题描述】:
我想在徽章中增加一个数字。
我在 'app.js' 中设置了数字 0。
我制作了减号按钮、加号按钮和文本框。
文本框中有一个数字。
如果我点击减号或加号按钮,数字会改变。
我在按钮点击功能中添加了一个动作。
但徽章中的数字没有改变。
这是我更改号码的代码。
example.controller('EventController', ['$scope', function($scope) {
$scope.count = 0;
$scope.countBadge = 0;
$scope.$on('orderMinus', function() {
if($scope.count!=0){
$scope.count--;
}
if($scope.countBadge != 0){
$scope.countBadge--;
}
});
$scope.$on('orderPlus', function() {
if($scope.count<=29){
$scope.count++;
$scope.countBadge++;
}
});
}]);
<script id="page_dish.html" type="text/ng-template">
<div>
<ion-header-bar style="height:10%; background: none; border-bottom: none">
<a id = "button_menuList" href="#/page_menuList"></a>
<a id = "img_chopchop"></a>
<div ng-controller="EventController">
<span class="badge badge-assertive">{{countBadge}}</span>
</div>
<a id = "button_basket" href="#/page_join"></a>
</ion-header-bar>
</div>
<ion-view class = "page_dish" ng-controller="AppCtrl">
<ion-content class = "no-header no-footer" has-bouncing="false">
<ion-slide-box>
<ion-slide class = "episode1">
<div align = "left">
<img src="img/Episode/Main/Episode1/Text_title.png" style="width:80%; margin-left:5%; margin-top:25%;">
<img src="img/Episode/Main/Episode1/Label_price.png" style="width:40%; margin-left:5%; margin-top:4%;">
</div>
<div>
<a id = "button_learnMore1" ng-click="modal.show()"></a>
</div>
<div align = "left" ng-controller="EventController">
<a class = "button_minus1" ng-click="$emit('orderMinus')"></a>
<input type="text" style="position:absolute; width:95px; height:65px; margin-left:37.4%; font-size:55px; color:#ffffff; background-color:transparent; text-align:center;" value = {{count}} readonly = "true">
<a class = "button_plus1" ng-click="$emit('orderPlus')"></a>
</div>
</ion-slide>
</ion-slide-box>
</ion-content>
</ion-view>
</script>
如何修复我的代码以通过单击按钮更改徽章中的数字。
请帮帮我。
【问题讨论】:
-
您的标题栏和内容容器正在使用 2 个单独的控制器分配。两个控制器彼此都不知道。您应该为它们都使用 1 个控制器(在一个公共父元素上),或者使用某种方式在两个控制器实例之间进行通信。
标签: javascript ionic badge