![](/img/trans.png)
[英]Small problem with hamburger, but I don't see it. Help me to find error please
[英]AngularJS small test, help me find the error please
http://codepen.io/rcidaleassumpo/pen/ogvoQy
您好,代码在上面的网站上。
多数民众赞成在HTML
<div ng-app="testApp" ng-controller="myController">
<select name="current" id="current" ng-model="currentliga">
<option ng-repeat="liga in ligas">{{ liga }}</option>
</select>
{{ valor | currency:"R$" }}
</div>
多数民众赞成在JS:
var app = angular.module('testApp', []);
app.controller('myController', function($scope){
$scope.ligas = ['Bronze', 'Prata', 'Ouro', 'Platina', 'Diamante'];
var preco = $scope.currentliga;
switch(preco){
case 'Bronze':
$scope.valor = 24;
break;
}
});
因此,基本上我的想法是从$ scope.currentLiga中获取值,该值与用户将要设置的选项链接在一起,然后为“ preco”返回一个值,该值将更改“ valor”。人们选择的“铜牌”,$ scope.valor应该更改为24。
使用$watch
:
var app = angular.module('testApp', []); app.controller('myController', function($scope) { $scope.ligas = ['Bronze', 'Prata', 'Ouro', 'Platina', 'Diamante']; $scope.$watch('currentliga', function(newValue, oldValue) { switch (newValue) { case 'Bronze': $scope.valor = 24; break; } }); });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="testApp" ng-controller="myController"> <select name="current" id="current" ng-model="currentliga"> <option ng-repeat="liga in ligas">{{ liga }}</option> </select> {{ valor | currency:"R$" }} </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.